Open wxm112 opened 2 years ago
I was able to do the following:
defer gock.Off()
gock.New("https://domain.com/").
Get("/initial").
Reply(302).
SetHeader("Location", "https://domain.com/redirected")
gock.New("https://domain.com/").
Get("/redirected").
Reply(200).
File("test.json")
// call API domain.com/initial and assert you get a 200 with the redirect body
assert.True(t, gock.IsDone())
When I mocked a response just with 301 status code, I got an error with a message: 301 response missing Location header. After adding the location header, there was another error with a message: gock: cannot match any request.
The code is shown as below: