From 9692140efa8f5130e6d9dfd502eff689416d9fa1 Mon Sep 17 00:00:00 2001 From: Steve Coffman Date: Sun, 26 May 2024 19:52:46 -0400 Subject: [PATCH] Autofixes Signed-off-by: Steve Coffman --- codegen/config/initialisms_test.go | 4 ++-- .../followschema/interfaces_test.go | 2 +- codegen/testserver/followschema/nulls_test.go | 2 +- .../testserver/singlefile/interfaces_test.go | 2 +- codegen/testserver/singlefile/nulls_test.go | 2 +- graphql/context_response_test.go | 2 +- graphql/executor/executor_test.go | 14 ++++++------- graphql/handler/extension/apq_test.go | 8 ++++---- graphql/handler/server_test.go | 8 ++++---- graphql/handler/transport/headers_test.go | 20 +++++++++---------- .../transport/http_form_multipart_test.go | 10 +++++----- graphql/handler_test.go | 2 +- internal/code/packages_test.go | 2 +- plugin/federation/federation_test.go | 8 ++++---- 14 files changed, 43 insertions(+), 43 deletions(-) diff --git a/codegen/config/initialisms_test.go b/codegen/config/initialisms_test.go index 13c0da2465..f18384a552 100644 --- a/codegen/config/initialisms_test.go +++ b/codegen/config/initialisms_test.go @@ -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) { diff --git a/codegen/testserver/followschema/interfaces_test.go b/codegen/testserver/followschema/interfaces_test.go index 3843212e36..15d2b380ef 100644 --- a/codegen/testserver/followschema/interfaces_test.go +++ b/codegen/testserver/followschema/interfaces_test.go @@ -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) diff --git a/codegen/testserver/followschema/nulls_test.go b/codegen/testserver/followschema/nulls_test.go index edd7237bb5..209d12b6c5 100644 --- a/codegen/testserver/followschema/nulls_test.go +++ b/codegen/testserver/followschema/nulls_test.go @@ -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) }) diff --git a/codegen/testserver/singlefile/interfaces_test.go b/codegen/testserver/singlefile/interfaces_test.go index 0fea26f35e..ea4e8e9070 100644 --- a/codegen/testserver/singlefile/interfaces_test.go +++ b/codegen/testserver/singlefile/interfaces_test.go @@ -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) diff --git a/codegen/testserver/singlefile/nulls_test.go b/codegen/testserver/singlefile/nulls_test.go index 0c9f568d63..dc95048999 100644 --- a/codegen/testserver/singlefile/nulls_test.go +++ b/codegen/testserver/singlefile/nulls_test.go @@ -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) }) diff --git a/graphql/context_response_test.go b/graphql/context_response_test.go index acafe95aae..578e6d57eb 100644 --- a/graphql/context_response_test.go +++ b/graphql/context_response_test.go @@ -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) diff --git a/graphql/executor/executor_test.go b/graphql/executor/executor_test.go index 9e15c5d46e..be81e2a4e0 100644 --- a/graphql/executor/executor_test.go +++ b/graphql/executor/executor_test.go @@ -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"]) }) }) @@ -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) { @@ -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) }) } diff --git a/graphql/handler/extension/apq_test.go b/graphql/handler/extension/apq_test.go index 33f2c7b15b..c231c2616a 100644 --- a/graphql/handler/extension/apq_test.go +++ b/graphql/handler/extension/apq_test.go @@ -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) }) @@ -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]) @@ -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]) @@ -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) }) diff --git a/graphql/handler/server_test.go b/graphql/handler/server_test.go index 232d13c56c..6e40c92d87 100644 --- a/graphql/handler/server_test.go +++ b/graphql/handler/server_test.go @@ -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) { @@ -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) }) } diff --git a/graphql/handler/transport/headers_test.go b/graphql/handler/transport/headers_test.go index 93fa4bf6b6..75876ab5a1 100644 --- a/graphql/handler/transport/headers_test.go +++ b/graphql/handler/transport/headers_test.go @@ -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")) }) @@ -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]) @@ -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")) }) @@ -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")) }) @@ -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")) }) @@ -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")) }) @@ -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")) }) @@ -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")) }) @@ -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")) }) @@ -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")) }) diff --git a/graphql/handler/transport/http_form_multipart_test.go b/graphql/handler/transport/http_form_multipart_test.go index 45656b504e..778f717b00 100644 --- a/graphql/handler/transport/http_form_multipart_test.go +++ b/graphql/handler/transport/http_form_multipart_test.go @@ -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"}`)}) } @@ -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"}`)}) } @@ -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}]}`)}) } @@ -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}]}`)}) } @@ -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}]}`)}) } diff --git a/graphql/handler_test.go b/graphql/handler_test.go index 38d9b45b4f..c6ed37a7be 100644 --- a/graphql/handler_test.go +++ b/graphql/handler_test.go @@ -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) }) diff --git a/internal/code/packages_test.go b/internal/code/packages_test.go index a51f1f1e80..e79ed1e3ba 100644 --- a/internal/code/packages_test.go +++ b/internal/code/packages_test.go @@ -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) diff --git a/plugin/federation/federation_test.go b/plugin/federation/federation_test.go index 7d912e0216..aff0d8f689 100644 --- a/plugin/federation/federation_test.go +++ b/plugin/federation/federation_test.go @@ -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) @@ -98,7 +98,7 @@ 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) { @@ -106,7 +106,7 @@ func TestUnusedInterfaceKeyDirective(t *testing.T) { err := f.MutateConfig(cfg) require.NoError(t, err) - require.Len(t, f.Entities, 0) + require.Empty(t, f.Entities) } func TestInterfaceKeyDirective(t *testing.T) { @@ -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())