Skip to content

Commit

Permalink
Autofixes
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Coffman <steve@khanacademy.org>
  • Loading branch information
StevenACoffman committed May 26, 2024
1 parent 57e88b2 commit 9692140
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 43 deletions.
4 changes: 2 additions & 2 deletions codegen/config/initialisms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ func TestGoInitialismsConfig(t *testing.T) {
t.Run("initialism config appends if desired", func(t *testing.T) {
tt := GoInitialismsConfig{ReplaceDefaults: false, Initialisms: []string{"ASDF"}}
result := tt.determineGoInitialisms()
assert.Equal(t, len(templates.CommonInitialisms)+1, len(result))
assert.Len(t, result, len(templates.CommonInitialisms)+1)
assert.True(t, result["ASDF"])
})
t.Run("initialism config replaces if desired", func(t *testing.T) {
tt := GoInitialismsConfig{ReplaceDefaults: true, Initialisms: []string{"ASDF"}}
result := tt.determineGoInitialisms()
assert.Equal(t, 1, len(result))
assert.Len(t, result, 1)
assert.True(t, result["ASDF"])
})
t.Run("initialism config uppercases the initialsms", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion codegen/testserver/followschema/interfaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func TestInterfaces(t *testing.T) {
}
`, &resp)

require.Equal(t, 2, len(resp.Shapes))
require.Len(t, resp.Shapes, 2)
require.Equal(t, float64(-1), resp.Shapes[0].Coordinates.X)
require.Equal(t, float64(0), resp.Shapes[0].Coordinates.Y)
require.Equal(t, float64(1), resp.Shapes[1].Coordinates.X)
Expand Down
2 changes: 1 addition & 1 deletion codegen/testserver/followschema/nulls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestNullBubbling(t *testing.T) {
err := c.Post(`query { valid, errorList { id } }`, &resp)

require.NoError(t, err)
require.Equal(t, 1, len(resp.ErrorList))
require.Len(t, resp.ErrorList, 1)
require.Nil(t, resp.ErrorList[0])
require.Equal(t, "Ok", resp.Valid)
})
Expand Down
2 changes: 1 addition & 1 deletion codegen/testserver/singlefile/interfaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func TestInterfaces(t *testing.T) {
}
`, &resp)

require.Equal(t, 2, len(resp.Shapes))
require.Len(t, resp.Shapes, 2)
require.Equal(t, float64(-1), resp.Shapes[0].Coordinates.X)
require.Equal(t, float64(0), resp.Shapes[0].Coordinates.Y)
require.Equal(t, float64(1), resp.Shapes[1].Coordinates.X)
Expand Down
2 changes: 1 addition & 1 deletion codegen/testserver/singlefile/nulls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestNullBubbling(t *testing.T) {
err := c.Post(`query { valid, errorList { id } }`, &resp)

require.NoError(t, err)
require.Equal(t, 1, len(resp.ErrorList))
require.Len(t, resp.ErrorList, 1)
require.Nil(t, resp.ErrorList[0])
require.Equal(t, "Ok", resp.Valid)
})
Expand Down
2 changes: 1 addition & 1 deletion graphql/context_response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestGetErrorFromPresenter(t *testing.T) {
errs := GetErrors(ctx)

// because we are still presenting the error it is not expected to be returned, but this should not deadlock.
require.Len(t, errs, 0)
require.Empty(t, errs)
return DefaultErrorPresenter(ctx, err)
}, nil)

Expand Down
14 changes: 7 additions & 7 deletions graphql/executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ func TestExecutor(t *testing.T) {
t.Run("no operation", func(t *testing.T) {
resp := query(exec, "", "")
assert.Equal(t, "", string(resp.Data))
assert.Equal(t, 1, len(resp.Errors))
assert.Len(t, resp.Errors, 1)
assert.Equal(t, errcode.ValidationFailed, resp.Errors[0].Extensions["code"])
})

t.Run("bad operation", func(t *testing.T) {
resp := query(exec, "badOp", "query test { name }")
assert.Equal(t, "", string(resp.Data))
assert.Equal(t, 1, len(resp.Errors))
assert.Len(t, resp.Errors, 1)
assert.Equal(t, errcode.ValidationFailed, resp.Errors[0].Extensions["code"])
})
})
Expand Down Expand Up @@ -134,9 +134,9 @@ func TestExecutor(t *testing.T) {

resp := query(exec, "", "invalid")
assert.Equal(t, "", string(resp.Data))
assert.Equal(t, 1, len(resp.Errors))
assert.Equal(t, 1, len(errors1))
assert.Equal(t, 1, len(errors2))
assert.Len(t, resp.Errors, 1)
assert.Len(t, errors1, 1)
assert.Len(t, errors2, 1)
})

t.Run("query caching", func(t *testing.T) {
Expand Down Expand Up @@ -216,8 +216,8 @@ func TestErrorServer(t *testing.T) {

resp := query(exec, "", "{name}")
assert.Equal(t, "null", string(resp.Data))
assert.Equal(t, 1, len(errors1))
assert.Equal(t, 1, len(errors2))
assert.Len(t, errors1, 1)
assert.Len(t, errors2, 1)
})
}

Expand Down
8 changes: 4 additions & 4 deletions graphql/handler/extension/apq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestAPQ(t *testing.T) {
Query: "original query",
}
err := extension.AutomaticPersistedQuery{graphql.MapCache{}}.MutateOperationParameters(ctx, params)
require.Nil(t, err)
require.NoError(t, err)

require.Equal(t, "original query", params.Query)
})
Expand Down Expand Up @@ -76,7 +76,7 @@ func TestAPQ(t *testing.T) {
}
cache := graphql.MapCache{}
err := extension.AutomaticPersistedQuery{cache}.MutateOperationParameters(ctx, params)
require.Nil(t, err)
require.NoError(t, err)

require.Equal(t, "{ me { name } }", params.Query)
require.Equal(t, "{ me { name } }", cache[hash])
Expand All @@ -95,7 +95,7 @@ func TestAPQ(t *testing.T) {
}
cache := graphql.MapCache{}
err := extension.AutomaticPersistedQuery{cache}.MutateOperationParameters(ctx, params)
require.Nil(t, err)
require.NoError(t, err)

require.Equal(t, "{ me { name } }", params.Query)
require.Equal(t, "{ me { name } }", cache[hash])
Expand All @@ -115,7 +115,7 @@ func TestAPQ(t *testing.T) {
hash: query,
}
err := extension.AutomaticPersistedQuery{cache}.MutateOperationParameters(ctx, params)
require.Nil(t, err)
require.NoError(t, err)

require.Equal(t, "{ me { name } }", params.Query)
})
Expand Down
8 changes: 4 additions & 4 deletions graphql/handler/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ func TestServer(t *testing.T) {

resp := get(srv, "/foo?query=invalid")
assert.Equal(t, http.StatusUnprocessableEntity, resp.Code, resp.Body.String())
assert.Equal(t, 1, len(errors1))
assert.Equal(t, 1, len(errors2))
assert.Len(t, errors1, 1)
assert.Len(t, errors2, 1)
})

t.Run("query caching", func(t *testing.T) {
Expand Down Expand Up @@ -159,8 +159,8 @@ func TestErrorServer(t *testing.T) {

resp := get(srv, "/foo?query={name}")
assert.Equal(t, http.StatusOK, resp.Code, resp.Body.String())
assert.Equal(t, 1, len(errors1))
assert.Equal(t, 1, len(errors2))
assert.Len(t, errors1, 1)
assert.Len(t, errors2, 1)
})
}

Expand Down
20 changes: 10 additions & 10 deletions graphql/handler/transport/headers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestHeadersWithPOST(t *testing.T) {

resp := doRequest(h, "POST", "/graphql", `{"query":"{ name }"}`, "application/json")
assert.Equal(t, http.StatusOK, resp.Code)
assert.Equal(t, 1, len(resp.Header()))
assert.Len(t, resp.Header(), 1)
assert.Equal(t, "application/json", resp.Header().Get("Content-Type"))
})

Expand All @@ -39,7 +39,7 @@ func TestHeadersWithPOST(t *testing.T) {

resp := doRequest(h, "POST", "/graphql", `{"query":"{ name }"}`, "application/json")
assert.Equal(t, http.StatusOK, resp.Code)
assert.Equal(t, 2, len(resp.Header()))
assert.Len(t, resp.Header(), 2)
assert.Equal(t, "application/json; charset: utf8", resp.Header().Get("Content-Type"))
assert.Equal(t, "dummy-post", resp.Header().Get("Other-Header"))
assert.Equal(t, "another-one", resp.Header().Values("Other-Header")[1])
Expand All @@ -53,7 +53,7 @@ func TestHeadersWithGET(t *testing.T) {

resp := doRequest(h, "GET", "/graphql?query={name}", "", "application/json")
assert.Equal(t, http.StatusOK, resp.Code)
assert.Equal(t, 1, len(resp.Header()))
assert.Len(t, resp.Header(), 1)
assert.Equal(t, "application/json", resp.Header().Get("Content-Type"))
})

Expand All @@ -68,7 +68,7 @@ func TestHeadersWithGET(t *testing.T) {

resp := doRequest(h, "GET", "/graphql?query={name}", "", "application/json")
assert.Equal(t, http.StatusOK, resp.Code)
assert.Equal(t, 2, len(resp.Header()))
assert.Len(t, resp.Header(), 2)
assert.Equal(t, "application/json; charset: utf8", resp.Header().Get("Content-Type"))
assert.Equal(t, "dummy-get", resp.Header().Get("Other-Header"))
})
Expand All @@ -81,7 +81,7 @@ func TestHeadersWithGRAPHQL(t *testing.T) {

resp := doRequest(h, "POST", "/graphql", `{ name }`, "application/graphql")
assert.Equal(t, http.StatusOK, resp.Code)
assert.Equal(t, 1, len(resp.Header()))
assert.Len(t, resp.Header(), 1)
assert.Equal(t, "application/json", resp.Header().Get("Content-Type"))
})

Expand All @@ -96,7 +96,7 @@ func TestHeadersWithGRAPHQL(t *testing.T) {

resp := doRequest(h, "POST", "/graphql", `{ name }`, "application/graphql")
assert.Equal(t, http.StatusOK, resp.Code)
assert.Equal(t, 2, len(resp.Header()))
assert.Len(t, resp.Header(), 2)
assert.Equal(t, "application/json; charset: utf8", resp.Header().Get("Content-Type"))
assert.Equal(t, "dummy-get-qraphql", resp.Header().Get("Other-Header"))
})
Expand All @@ -109,7 +109,7 @@ func TestHeadersWithFormUrlEncoded(t *testing.T) {

resp := doRequest(h, "POST", "/graphql", `{ name }`, "application/x-www-form-urlencoded")
assert.Equal(t, http.StatusOK, resp.Code)
assert.Equal(t, 1, len(resp.Header()))
assert.Len(t, resp.Header(), 1)
assert.Equal(t, "application/json", resp.Header().Get("Content-Type"))
})

Expand All @@ -124,7 +124,7 @@ func TestHeadersWithFormUrlEncoded(t *testing.T) {

resp := doRequest(h, "POST", "/graphql", `{ name }`, "application/x-www-form-urlencoded")
assert.Equal(t, http.StatusOK, resp.Code)
assert.Equal(t, 2, len(resp.Header()))
assert.Len(t, resp.Header(), 2)
assert.Equal(t, "application/json; charset: utf8", resp.Header().Get("Content-Type"))
assert.Equal(t, "dummy-get-urlencoded-form", resp.Header().Get("Other-Header"))
})
Expand Down Expand Up @@ -168,7 +168,7 @@ func TestHeadersWithMULTIPART(t *testing.T) {
resp := httptest.NewRecorder()
h.ServeHTTP(resp, req)
require.Equal(t, http.StatusOK, resp.Code, resp.Body.String())
assert.Equal(t, 1, len(resp.Header()))
assert.Len(t, resp.Header(), 1)
assert.Equal(t, "application/json", resp.Header().Get("Content-Type"))
})

Expand Down Expand Up @@ -213,7 +213,7 @@ func TestHeadersWithMULTIPART(t *testing.T) {
resp := httptest.NewRecorder()
h.ServeHTTP(resp, req)
require.Equal(t, http.StatusOK, resp.Code, resp.Body.String())
assert.Equal(t, 2, len(resp.Header()))
assert.Len(t, resp.Header(), 2)
assert.Equal(t, "application/json; charset: utf8", resp.Header().Get("Content-Type"))
assert.Equal(t, "dummy-multipart", resp.Header().Get("Other-Header"))
})
Expand Down
10 changes: 5 additions & 5 deletions graphql/handler/transport/http_form_multipart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestFileUpload(t *testing.T) {
t.Run("valid single file upload", func(t *testing.T) {
es.ExecFunc = func(ctx context.Context) graphql.ResponseHandler {
op := graphql.GetOperationContext(ctx).Operation
require.Equal(t, 1, len(op.VariableDefinitions))
require.Len(t, op.VariableDefinitions, 1)
require.Equal(t, "file", op.VariableDefinitions[0].Variable)
return graphql.OneShot(&graphql.Response{Data: []byte(`{"singleUpload":"test"}`)})
}
Expand All @@ -72,7 +72,7 @@ func TestFileUpload(t *testing.T) {
t.Run("valid single file upload with payload", func(t *testing.T) {
es.ExecFunc = func(ctx context.Context) graphql.ResponseHandler {
op := graphql.GetOperationContext(ctx).Operation
require.Equal(t, 1, len(op.VariableDefinitions))
require.Len(t, op.VariableDefinitions, 1)
require.Equal(t, "req", op.VariableDefinitions[0].Variable)
return graphql.OneShot(&graphql.Response{Data: []byte(`{"singleUploadWithPayload":"test"}`)})
}
Expand All @@ -98,7 +98,7 @@ func TestFileUpload(t *testing.T) {
t.Run("valid file list upload", func(t *testing.T) {
es.ExecFunc = func(ctx context.Context) graphql.ResponseHandler {
op := graphql.GetOperationContext(ctx).Operation
require.Equal(t, 1, len(op.VariableDefinitions))
require.Len(t, op.VariableDefinitions, 1)
require.Equal(t, "files", op.VariableDefinitions[0].Variable)
return graphql.OneShot(&graphql.Response{Data: []byte(`{"multipleUpload":[{"id":1},{"id":2}]}`)})
}
Expand Down Expand Up @@ -130,7 +130,7 @@ func TestFileUpload(t *testing.T) {
t.Run("valid file list upload with payload", func(t *testing.T) {
es.ExecFunc = func(ctx context.Context) graphql.ResponseHandler {
op := graphql.GetOperationContext(ctx).Operation
require.Equal(t, 1, len(op.VariableDefinitions))
require.Len(t, op.VariableDefinitions, 1)
require.Equal(t, "req", op.VariableDefinitions[0].Variable)
return graphql.OneShot(&graphql.Response{Data: []byte(`{"multipleUploadWithPayload":[{"id":1},{"id":2}]}`)})
}
Expand Down Expand Up @@ -163,7 +163,7 @@ func TestFileUpload(t *testing.T) {
test := func(uploadMaxMemory int64) {
es.ExecFunc = func(ctx context.Context) graphql.ResponseHandler {
op := graphql.GetOperationContext(ctx).Operation
require.Equal(t, 1, len(op.VariableDefinitions))
require.Len(t, op.VariableDefinitions, 1)
require.Equal(t, "req", op.VariableDefinitions[0].Variable)
return graphql.OneShot(&graphql.Response{Data: []byte(`{"multipleUploadWithPayload":[{"id":1},{"id":2}]}`)})
}
Expand Down
2 changes: 1 addition & 1 deletion graphql/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestAddUploadToOperations(t *testing.T) {

path := "variables.req.0.file"
err := request.AddUpload(upload, key, path)
require.Nil(t, err)
require.NoError(t, err)

require.Equal(t, expected, request)
})
Expand Down
2 changes: 1 addition & 1 deletion internal/code/packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func initialState(t *testing.T, opts ...Option) *Packages {
"github.com/99designs/gqlgen/internal/code/testdata/a",
"github.com/99designs/gqlgen/internal/code/testdata/b",
)
require.Nil(t, p.Errors())
require.NoError(t, p.Errors())

require.Equal(t, 1, p.numLoadCalls)
require.Equal(t, 0, p.numNameCalls)
Expand Down
8 changes: 4 additions & 4 deletions plugin/federation/federation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestWithEntities(t *testing.T) {
require.Equal(t, "String", f.Entities[1].Resolvers[0].KeyFields[0].Definition.Type.Name())

require.Equal(t, "MoreNesting", f.Entities[2].Name)
require.Len(t, f.Entities[2].Resolvers, 0)
require.Empty(t, f.Entities[2].Resolvers)

require.Equal(t, "MultiHelloMultiKey", f.Entities[3].Name)
require.Len(t, f.Entities[3].Resolvers, 2)
Expand Down Expand Up @@ -98,15 +98,15 @@ func TestNoEntities(t *testing.T) {

err := f.MutateConfig(cfg)
require.NoError(t, err)
require.Len(t, f.Entities, 0)
require.Empty(t, f.Entities)
}

func TestUnusedInterfaceKeyDirective(t *testing.T) {
f, cfg := load(t, "testdata/interfaces/unused_key.yml")

err := f.MutateConfig(cfg)
require.NoError(t, err)
require.Len(t, f.Entities, 0)
require.Empty(t, f.Entities)
}

func TestInterfaceKeyDirective(t *testing.T) {
Expand Down Expand Up @@ -209,7 +209,7 @@ func TestMultiWithOmitSliceElemPointersCfg(t *testing.T) {

func TestHandlesRequiresArgumentCorrectlyIfNoSpace(t *testing.T) {
requiresFieldSet := fieldset.New("foo bar baz(limit:4)", nil)
assert.Equal(t, 3, len(requiresFieldSet))
assert.Len(t, requiresFieldSet, 3)
assert.Equal(t, "Foo", requiresFieldSet[0].ToGo())
assert.Equal(t, "Bar", requiresFieldSet[1].ToGo())
assert.Equal(t, "Baz(limit:4)", requiresFieldSet[2].ToGo())
Expand Down

0 comments on commit 9692140

Please sign in to comment.