Skip to content

Commit

Permalink
Hardcode string as type in integration test helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
HaraldNordgren committed Sep 28, 2024
1 parent ba691ea commit d9a21e2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
32 changes: 16 additions & 16 deletions internal/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestSimpleQuery(t *testing.T) {
ctx := context.Background()
server := server.RunServer()
defer server.Close()
clients := newRoundtripClients[string](t, server.URL)
clients := newRoundtripClients(t, server.URL)

for _, client := range clients {
resp, _, err := simpleQuery(ctx, client)
Expand All @@ -45,8 +45,8 @@ func TestMutation(t *testing.T) {
ctx := context.Background()
server := server.RunServer()
defer server.Close()
postClient := newRoundtripClient[string](t, server.URL)
getClient := newRoundtripGetClient[string](t, server.URL)
postClient := newRoundtripClient(t, server.URL)
getClient := newRoundtripGetClient(t, server.URL)

resp, _, err := createUser(ctx, postClient, NewUser{Name: "Jack"})
require.NoError(t, err)
Expand Down Expand Up @@ -105,7 +105,7 @@ func TestServerError(t *testing.T) {
ctx := context.Background()
server := server.RunServer()
defer server.Close()
clients := newRoundtripClients[string](t, server.URL)
clients := newRoundtripClients(t, server.URL)

for _, client := range clients {
resp, _, err := failingQuery(ctx, client)
Expand All @@ -120,7 +120,7 @@ func TestServerError(t *testing.T) {

func TestNetworkError(t *testing.T) {
ctx := context.Background()
clients := newRoundtripClients[string](t, "https://nothing.invalid/graphql")
clients := newRoundtripClients(t, "https://nothing.invalid/graphql")

for _, client := range clients {
resp, _, err := failingQuery(ctx, client)
Expand Down Expand Up @@ -174,7 +174,7 @@ func TestExtensions(t *testing.T) {
ctx := context.Background()
server := server.RunServer()
defer server.Close()
clients := newRoundtripClients[string](t, server.URL)
clients := newRoundtripClients(t, server.URL)

for _, client := range clients {
_, extensions, err := simpleQueryExt(ctx, client)
Expand All @@ -193,7 +193,7 @@ func TestOmitempty(t *testing.T) {
ctx := context.Background()
server := server.RunServer()
defer server.Close()
clients := newRoundtripClients[string](t, server.URL)
clients := newRoundtripClients(t, server.URL)

for _, client := range clients {
resp, _, err := queryWithOmitempty(ctx, client, "2")
Expand Down Expand Up @@ -222,7 +222,7 @@ func TestCustomMarshal(t *testing.T) {
ctx := context.Background()
server := server.RunServer()
defer server.Close()
clients := newRoundtripClients[string](t, server.URL)
clients := newRoundtripClients(t, server.URL)

for _, client := range clients {
resp, _, err := queryWithCustomMarshal(ctx, client,
Expand Down Expand Up @@ -253,7 +253,7 @@ func TestCustomMarshalSlice(t *testing.T) {
ctx := context.Background()
server := server.RunServer()
defer server.Close()
clients := newRoundtripClients[string](t, server.URL)
clients := newRoundtripClients(t, server.URL)

for _, client := range clients {
resp, _, err := queryWithCustomMarshalSlice(ctx, client,
Expand Down Expand Up @@ -289,7 +289,7 @@ func TestCustomMarshalOptional(t *testing.T) {
ctx := context.Background()
server := server.RunServer()
defer server.Close()
clients := newRoundtripClients[string](t, server.URL)
clients := newRoundtripClients(t, server.URL)

for _, client := range clients {
date := time.Date(2025, time.January, 1, 12, 34, 56, 789, time.UTC)
Expand Down Expand Up @@ -325,7 +325,7 @@ func TestInterfaceNoFragments(t *testing.T) {
ctx := context.Background()
server := server.RunServer()
defer server.Close()
clients := newRoundtripClients[string](t, server.URL)
clients := newRoundtripClients(t, server.URL)

for _, client := range clients {
resp, _, err := queryWithInterfaceNoFragments(ctx, client, "1")
Expand Down Expand Up @@ -390,7 +390,7 @@ func TestInterfaceListField(t *testing.T) {
ctx := context.Background()
server := server.RunServer()
defer server.Close()
clients := newRoundtripClients[string](t, server.URL)
clients := newRoundtripClients(t, server.URL)

for _, client := range clients {
resp, _, err := queryWithInterfaceListField(ctx, client,
Expand Down Expand Up @@ -439,7 +439,7 @@ func TestInterfaceListPointerField(t *testing.T) {
ctx := context.Background()
server := server.RunServer()
defer server.Close()
clients := newRoundtripClients[string](t, server.URL)
clients := newRoundtripClients(t, server.URL)

for _, client := range clients {
resp, _, err := queryWithInterfaceListPointerField(ctx, client,
Expand Down Expand Up @@ -495,7 +495,7 @@ func TestFragments(t *testing.T) {
ctx := context.Background()
server := server.RunServer()
defer server.Close()
clients := newRoundtripClients[string](t, server.URL)
clients := newRoundtripClients(t, server.URL)

for _, client := range clients {
resp, _, err := queryWithFragments(ctx, client, []string{"1", "3", "12847394823"})
Expand Down Expand Up @@ -590,7 +590,7 @@ func TestNamedFragments(t *testing.T) {
ctx := context.Background()
server := server.RunServer()
defer server.Close()
clients := newRoundtripClients[string](t, server.URL)
clients := newRoundtripClients(t, server.URL)

for _, client := range clients {
resp, _, err := queryWithNamedFragments(ctx, client, []string{"1", "3", "12847394823"})
Expand Down Expand Up @@ -721,7 +721,7 @@ func TestFlatten(t *testing.T) {
ctx := context.Background()
server := server.RunServer()
defer server.Close()
clients := newRoundtripClients[string](t, server.URL)
clients := newRoundtripClients(t, server.URL)

for _, client := range clients {
resp, _, err := queryWithFlatten(ctx, client, []string{"1", "3", "12847394823"})
Expand Down
14 changes: 7 additions & 7 deletions internal/integration/roundtrip.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (c *roundtripClient[_]) roundtripResponse(resp interface{}) {
assert.Equal(c.t, string(body), string(bodyAgain))
}

func (c *roundtripClient[T]) MakeRequest(ctx context.Context, req *graphql.Request, resp *graphql.Response) error {
func (c *roundtripClient[_]) MakeRequest(ctx context.Context, req *graphql.Request, resp *graphql.Response) error {
// TODO(benkraft): Also check the variables round-trip. This is a bit less
// important since most of the code is the same (and input types are
// strictly simpler), and a bit hard to do because when asserting about
Expand Down Expand Up @@ -122,24 +122,24 @@ func (c *roundtripClient[_]) Unsubscribe(subscriptionID string) error {
return c.wsWrapped.Unsubscribe(subscriptionID)
}

func newRoundtripClients[T any](t *testing.T, endpoint string) []graphql.Client {
return []graphql.Client{newRoundtripClient[T](t, endpoint), newRoundtripGetClient[T](t, endpoint)}
func newRoundtripClients(t *testing.T, endpoint string) []graphql.Client {
return []graphql.Client{newRoundtripClient(t, endpoint), newRoundtripGetClient(t, endpoint)}
}

func newRoundtripClient[T any](t *testing.T, endpoint string) graphql.Client {
func newRoundtripClient(t *testing.T, endpoint string) graphql.Client {
transport := &lastResponseTransport{wrapped: http.DefaultTransport}
httpClient := &http.Client{Transport: transport}
return &roundtripClient[T]{
return &roundtripClient[string]{
wrapped: graphql.NewClient(endpoint, httpClient),
transport: transport,
t: t,
}
}

func newRoundtripGetClient[T any](t *testing.T, endpoint string) graphql.Client {
func newRoundtripGetClient(t *testing.T, endpoint string) graphql.Client {
transport := &lastResponseTransport{wrapped: http.DefaultTransport}
httpClient := &http.Client{Transport: transport}
return &roundtripClient[T]{
return &roundtripClient[string]{
wrapped: graphql.NewClientUsingGet(endpoint, httpClient),
transport: transport,
t: t,
Expand Down

0 comments on commit d9a21e2

Please sign in to comment.