-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(gqlclient): improve test suite, allow structs for variables (#4
- Loading branch information
Showing
9 changed files
with
344 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ categories: | |
labels: | ||
- documentation | ||
- title: 🧰 Maintenance | ||
label: | ||
labels: | ||
- ci | ||
- chore | ||
template: | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package gqlclient | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNew(t *testing.T) { | ||
srv := mockServer(t) | ||
|
||
client := New(srv.URL) | ||
|
||
var data struct { | ||
ID string | ||
Name string | ||
} | ||
|
||
resp, err := client.Send(&data, `query GetUser { user(id: $id) { id name } }`, map[string]interface{}{ | ||
"id": "1", | ||
}) | ||
|
||
require.NoError(t, err) | ||
|
||
require.Equal(t, []Error(nil), resp.Errors) | ||
require.Equal(t, "bob", data.Name) | ||
} | ||
|
||
func TestClient_WithHTTPClient(t *testing.T) { | ||
srv := mockServer(t) | ||
|
||
client := New(srv.URL) | ||
|
||
client.WithHTTPClient(http.DefaultClient) | ||
|
||
var data struct { | ||
ID string | ||
Name string | ||
} | ||
|
||
_, err := client.Send(&data, `query GetUser { user(id: $id) { id name } }`, map[string]interface{}{ | ||
"id": "1", | ||
}) | ||
|
||
require.NoError(t, err) | ||
} |
Oops, something went wrong.