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