Registering more than 5 responders
SoheilSalehian opened this issue · 2 comments
Hi all,
I have been running into indeterministic behavior while setting up multiple responders for a single test. To give you more context, the handler I am testing actually makes external request to 6 different endpoints, gathers the result. Here's the test code:
func TestEndpoint(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
fakeResponseJsonA := []byte(`{"result": "fake-result"}`)
url := fmt.Sprintf("%s/fakeA", os.Getenv("FAKE_A"))
httpmock.RegisterResponder(http.MethodPost, url, httpmock.NewBytesResponder(http.StatusOK, fakeA))
fakeResponseJsonB:= []byte(`{"result": "fake-result"}`)
url := fmt.Sprintf("%s/fakeB", os.Getenv("FAKE_B"))
httpmock.RegisterResponder(http.MethodPost, url, httpmock.NewBytesResponder(http.StatusOK, fakeB))
...
Changing the order of the httpmock.RegisterResponder
calls result in no responder found
errors. In the past I was able to make this work for 4 calls in a test but it looks like I am hitting an edge case. Any ideas why this might be happening?
Using Go1.11.4 with GorillaMux with httpmock.v1
Hi @SoheilSalehian
Do you have a simple test file to reproduce the problem?
Thanks for your response @maxatome!
Found the problem: the environment variables for the base urls were empty for all responders. Had to set a couple of them up that were colliding.
Closing this.