diff --git a/gh_test.go b/gh_test.go index a9e5b93..781c4c4 100644 --- a/gh_test.go +++ b/gh_test.go @@ -106,6 +106,7 @@ func TestGQLClient(t *testing.T) { } func TestGQLClientError(t *testing.T) { + t.Cleanup(gock.Off) tempDir := t.TempDir() orig_GH_CONFIG_DIR := os.Getenv("GH_CONFIG_DIR") orig_GH_TOKEN := os.Getenv("GH_TOKEN") @@ -116,19 +117,20 @@ func TestGQLClientError(t *testing.T) { os.Setenv("GH_CONFIG_DIR", tempDir) os.Setenv("GH_TOKEN", "GH_TOKEN") - http := httpmock.NewRegistry(t) - http.Register( - httpmock.GQL("QUERY"), - httpmock.StringResponse(`{"errors":[{"type":"NOT_FOUND","path":["organization"],"message":"Could not resolve to an Organization with the login of 'cli'."}]}`), - ) + gock.New("https://api.github.com"). + Post("/graphql"). + MatchHeader("Authorization", "token GH_TOKEN"). + BodyString(`{"query":"QUERY","variables":null}`). + Reply(200). + JSON(`{"errors":[{"type":"NOT_FOUND","path":["organization"],"message":"Could not resolve to an Organization with the login of 'cli'."}]}`) - client, err := GQLClient(&api.ClientOptions{Transport: http}) + client, err := GQLClient(nil) assert.NoError(t, err) - vars := map[string]interface{}{} res := struct{ Organization struct{ Name string } }{} - err = client.Do("QUERY", vars, &res) + err = client.Do("QUERY", nil, &res) assert.EqualError(t, err, "GQL error: Could not resolve to an Organization with the login of 'cli'.") + assert.True(t, gock.IsDone(), printPendingMocks(gock.Pending())) } func TestHTTPClient(t *testing.T) {