Skip to content

Commit 4c2f647

Browse files
committed
array
1 parent 275f992 commit 4c2f647

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

framework/components/fake/record.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ type Record struct {
2323
}
2424

2525
type Records struct {
26-
r map[string]*Record
26+
r map[string][]*Record
2727
}
2828

2929
func NewRecords() *Records {
30-
return &Records{make(map[string]*Record)}
30+
return &Records{make(map[string][]*Record)}
3131
}
3232

33-
func (r *Records) Get(path string) (*Record, error) {
33+
func (r *Records) Get(path string) ([]*Record, error) {
3434
rec, ok := r.r[path]
3535
if !ok {
3636
return nil, fmt.Errorf("no record was found for path: %s", path)
@@ -74,13 +74,17 @@ func recordMiddleware() gin.HandlerFunc {
7474
// Capture response data
7575
resBody := customWriter.body.String()
7676
status := c.Writer.Status()
77-
R.r[c.Request.URL.Path] = &Record{
77+
if R.r[c.Request.URL.Path] == nil {
78+
R.r[c.Request.URL.Path] = make([]*Record, 0)
79+
}
80+
R.r[c.Request.URL.Path] = append(R.r[c.Request.URL.Path], &Record{
7881
Method: c.Request.Method,
7982
Path: c.Request.URL.Path,
8083
Headers: c.Request.Header,
8184
ReqBody: reqBody,
8285
ResBody: resBody,
8386
Status: status,
84-
}
87+
},
88+
)
8589
}
8690
}

framework/components/fake/record_test.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,20 @@ func TestComponentFake(t *testing.T) {
5050

5151
// get request and response
5252
recordedData, err := fake.R.Get(apiPath)
53-
require.Equal(t, &fake.Record{
54-
Method: "POST",
55-
Path: apiPath,
56-
Headers: http.Header{
57-
"Accept-Encoding": []string{"gzip"},
58-
"Content-Type": []string{"application/json"},
59-
"Content-Length": []string{"25"},
60-
"User-Agent": []string{"go-resty/2.15.3 (https://github.com/go-resty/resty)"},
53+
require.Equal(t, []*fake.Record{
54+
{
55+
Method: "POST",
56+
Path: apiPath,
57+
Headers: http.Header{
58+
"Accept-Encoding": []string{"gzip"},
59+
"Content-Type": []string{"application/json"},
60+
"Content-Length": []string{"25"},
61+
"User-Agent": []string{"go-resty/2.15.3 (https://github.com/go-resty/resty)"},
62+
},
63+
ReqBody: `{"some_data":"some_data"}`,
64+
ResBody: `{"status":"ok"}`,
65+
Status: 200,
6166
},
62-
ReqBody: `{"some_data":"some_data"}`,
63-
ResBody: `{"status":"ok"}`,
64-
Status: 200,
6567
}, recordedData)
6668
})
6769
}

0 commit comments

Comments
 (0)