-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmocked_response_test.go
More file actions
106 lines (92 loc) · 2.1 KB
/
mocked_response_test.go
File metadata and controls
106 lines (92 loc) · 2.1 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package awsmocker
import (
"maps"
"reflect"
"testing"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/sts"
"github.com/stretchr/testify/require"
)
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)
})
}
}
func TestProcessDirectRequestFunc(t *testing.T) {
entry := mwDBEntry{
Parameters: &sts.GetCallerIdentityInput{},
}
rr := &ReceivedRequest{}
stsResponse := &sts.GetCallerIdentityOutput{
Account: aws.String(DefaultAccountId),
Arn: aws.String("arn"),
UserId: aws.String("userid"),
}
tables := []struct {
fn any
}{
{
fn: func(_ *sts.GetCallerIdentityInput) (*sts.GetCallerIdentityOutput, error) {
return stsResponse, nil
},
},
{
fn: func(_ *ReceivedRequest) (*sts.GetCallerIdentityOutput, error) {
return stsResponse, nil
},
},
{
fn: func(_ *ReceivedRequest, _ *sts.GetCallerIdentityInput) (*sts.GetCallerIdentityOutput, error) {
return stsResponse, nil
},
},
{
fn: func() *sts.GetCallerIdentityOutput {
return stsResponse
},
},
}
for _, table := range tables {
t.Run("entry", func(t *testing.T) {
result, err := processDirectRequestFunc(entry, rr, reflect.ValueOf(table.fn))
_ = result
_ = err
})
}
}