Closed harobed closed 6 years ago
I will look into it -- at the moment I don't support mocking the library
@harobed At least for me it works like charm. Below I implemented the simple mocking available at gock readme just changing the http call:
package test
import (
"testing"
"github.com/h2non/gock"
"github.com/levigross/grequests"
"github.com/nbio/st"
)
func TestSimple(t *testing.T) {
defer gock.Off()
gock.New("http://foo.com").
Get("/bar").
Reply(200).
JSON(map[string]string{"foo": "bar"})
res, err := grequests.Get("http://foo.com/bar", nil)
st.Expect(t, err, nil)
st.Expect(t, res.StatusCode, 200)
body := res.Bytes()
st.Expect(t, string(body)[:13], `{"foo":"bar"}`)
// Verify that we don't have pending mocks
st.Expect(t, gock.IsDone(), true)
}
I don't know if it helps you :)
Thanks :)
Hi,
how can I mock http service with h2non/gock and
levigross/grequests
?Best regards, Stéphane