File tree Expand file tree Collapse file tree 2 files changed +22
-16
lines changed
framework/components/fake Expand file tree Collapse file tree 2 files changed +22
-16
lines changed Original file line number Diff line number Diff line change @@ -23,14 +23,14 @@ type Record struct {
2323}
2424
2525type Records struct {
26- r map [string ]* Record
26+ r map [string ][] * Record
2727}
2828
2929func 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}
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments