github.com/webdestroya/awsmocker@v0.2.6/mocked_response_test.go (about)

     1  package awsmocker
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  	"golang.org/x/exp/maps"
     8  )
     9  
    10  func TestMockedResponse_getResponse(t *testing.T) {
    11  
    12  	fakePayload := map[string]any{
    13  		"foo": map[string]any{
    14  			"baz": "thing",
    15  		},
    16  		"bar": 1234,
    17  		"b":   true,
    18  		"bf":  false,
    19  		"str": "some string",
    20  	}
    21  
    22  	tables := []struct {
    23  		name string
    24  		mr   *MockedResponse
    25  		rr   *ReceivedRequest
    26  		exp  func(*testing.T, *httpResponse)
    27  	}{
    28  		{
    29  			name: "XMLWrapped",
    30  			mr: &MockedResponse{
    31  				Body:     maps.Clone(fakePayload),
    32  				Encoding: ResponseEncodingXML,
    33  			},
    34  			rr: &ReceivedRequest{
    35  				Service: "sts",
    36  				Action:  "GetCallerIdentity",
    37  			},
    38  			exp: func(t *testing.T, hr *httpResponse) {
    39  				require.Equal(t, ContentTypeXML, hr.contentType)
    40  				bodyRaw := string(hr.bodyRaw)
    41  				require.Contains(t, bodyRaw, "<GetCallerIdentityResult>")
    42  				require.Contains(t, bodyRaw, "<GetCallerIdentityResponse>")
    43  			},
    44  		},
    45  	}
    46  
    47  	for _, table := range tables {
    48  		t.Run(table.name, func(t *testing.T) {
    49  			hr := table.mr.getResponse(table.rr)
    50  			table.exp(t, hr)
    51  		})
    52  	}
    53  }