Skip to content

Commit

Permalink
testifylint v1.3.0 fixes (#3103)
Browse files Browse the repository at this point in the history
* Resolve Merge conflict

Signed-off-by: Steve Coffman <[email protected]>

* Autofixes

Signed-off-by: Steve Coffman <[email protected]>

* Lots more fixes and formatting

Signed-off-by: Steve Coffman <[email protected]>

* Add one more

Signed-off-by: Steve Coffman <[email protected]>

* Apply suggestions from code review

Co-authored-by: Roman Dmytrenko <[email protected]>

---------

Signed-off-by: Steve Coffman <[email protected]>
Co-authored-by: Oleksandr Redko <[email protected]>
Co-authored-by: Roman Dmytrenko <[email protected]>
  • Loading branch information
3 people authored May 27, 2024
1 parent bbb0c95 commit b18d028
Show file tree
Hide file tree
Showing 21 changed files with 76 additions and 74 deletions.
3 changes: 1 addition & 2 deletions _examples/chat/chat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"sync"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/99designs/gqlgen/client"
Expand Down Expand Up @@ -50,7 +49,7 @@ func TestChatSubscriptions(t *testing.T) {
b:post(text:"Hello Vektah!", roomName:"#gophers%d", username:"andrey") { id }
c:post(text:"Whats up?", roomName:"#gophers%d", username:"vektah") { id }
}`, i, i, i), &resp)
assert.NoError(t, err)
require.NoError(t, err)
}()

msg.err = sub.Next(&msg.resp)
Expand Down
3 changes: 1 addition & 2 deletions api/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/99designs/gqlgen/codegen/config"
Expand Down Expand Up @@ -47,7 +46,7 @@ func TestGenerate(t *testing.T) {
cfg, err := config.LoadConfigFromDefaultLocations()
require.NoError(t, err, "failed to load config")
err = Generate(cfg)
assert.NoError(t, err, "failed to generate code")
require.NoError(t, err, "failed to generate code")
})
}
}
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
10 changes: 5 additions & 5 deletions codegen/testserver/followschema/interfaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,11 @@ func TestInterfaces(t *testing.T) {
}
`, &resp)

require.Equal(t, 2, len(resp.Shapes))
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)
require.Equal(t, float64(1), resp.Shapes[1].Coordinates.Y)
require.Len(t, resp.Shapes, 2)
require.InDelta(t, float64(-1), resp.Shapes[0].Coordinates.X, 0.02)
require.InDelta(t, float64(0), resp.Shapes[0].Coordinates.Y, 0.02)
require.InDelta(t, float64(1), resp.Shapes[1].Coordinates.X, 0.02)
require.InDelta(t, float64(1), resp.Shapes[1].Coordinates.Y, 0.02)
})

t.Run("fragment on interface must return merged fields", func(t *testing.T) {
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
10 changes: 5 additions & 5 deletions codegen/testserver/singlefile/interfaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,11 @@ func TestInterfaces(t *testing.T) {
}
`, &resp)

require.Equal(t, 2, len(resp.Shapes))
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)
require.Equal(t, float64(1), resp.Shapes[1].Coordinates.Y)
require.Len(t, resp.Shapes, 2)
require.InDelta(t, float64(-1), resp.Shapes[0].Coordinates.X, 0.02)
require.InDelta(t, float64(0), resp.Shapes[0].Coordinates.Y, 0.02)
require.InDelta(t, float64(1), resp.Shapes[1].Coordinates.X, 0.02)
require.InDelta(t, float64(1), resp.Shapes[1].Coordinates.Y, 0.02)
})

t.Run("fragment on interface must return merged fields", func(t *testing.T) {
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
5 changes: 3 additions & 2 deletions graphql/duration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestDurationMarshaling(t *testing.T) {
t.Run("UnmarshalDuration", func(t *testing.T) {
d, err := UnmarshalDuration("P2Y")
assert.NoError(t, err)
require.NoError(t, err)

assert.Equal(t, float64(365*24*2), d.Hours())
assert.InEpsilon(t, float64(365*24*2), d.Hours(), 0.02)
})
t.Run("MarshalDuration", func(t *testing.T) {
m := MarshalDuration(time.Hour * 365 * 24 * 2)
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
13 changes: 7 additions & 6 deletions graphql/handler/extension/apq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ func TestAPQ(t *testing.T) {
params := &graphql.RawParams{
Query: "original query",
}
err := extension.AutomaticPersistedQuery{graphql.MapCache{}}.MutateOperationParameters(ctx, params)
require.Equal(t, (*gqlerror.Error)(nil), err)

err := extension.AutomaticPersistedQuery{Cache: graphql.MapCache{}}.MutateOperationParameters(ctx, params)

require.Equal(t, (*gqlerror.Error)(nil), err)
require.Equal(t, "original query", params.Query)
})

Expand All @@ -60,7 +61,7 @@ func TestAPQ(t *testing.T) {
},
}

err := extension.AutomaticPersistedQuery{graphql.MapCache{}}.MutateOperationParameters(ctx, params)
err := extension.AutomaticPersistedQuery{Cache: graphql.MapCache{}}.MutateOperationParameters(ctx, params)
require.Equal(t, "PersistedQueryNotFound", err.Message)
})

Expand All @@ -76,9 +77,9 @@ func TestAPQ(t *testing.T) {
},
}
cache := graphql.MapCache{}
err := extension.AutomaticPersistedQuery{cache}.MutateOperationParameters(ctx, params)
require.Equal(t, (*gqlerror.Error)(nil), err)
err := extension.AutomaticPersistedQuery{Cache: cache}.MutateOperationParameters(ctx, params)

require.Equal(t, (*gqlerror.Error)(nil), err)
require.Equal(t, "{ me { name } }", params.Query)
require.Equal(t, "{ me { name } }", cache[hash])
})
Expand Down Expand Up @@ -116,8 +117,8 @@ func TestAPQ(t *testing.T) {
hash: query,
}
err := extension.AutomaticPersistedQuery{cache}.MutateOperationParameters(ctx, params)
require.Equal(t, (*gqlerror.Error)(nil), err)

require.Equal(t, (*gqlerror.Error)(nil), 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/transport/websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ func TestWebSocketInitTimeout(t *testing.T) {

var msg operationMessage
err := c.ReadJSON(&msg)
assert.Error(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), "timeout")
})

Expand Down
1 change: 0 additions & 1 deletion graphql/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ func TestAddUploadToOperations(t *testing.T) {
path := "variables.req.0.file"
err := request.AddUpload(upload, key, path)
require.Equal(t, (*gqlerror.Error)(nil), err)

require.Equal(t, expected, request)
})
}
Loading

0 comments on commit b18d028

Please sign in to comment.