Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testifylint v1.3.0 fixes #3103

Merged
merged 5 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Lots more fixes and formatting
Signed-off-by: Steve Coffman <steve@khanacademy.org>
  • Loading branch information
StevenACoffman committed May 27, 2024
commit 265204cf411daeb2d93e65a509f3e779e18e5967
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")
})
}
}
8 changes: 4 additions & 4 deletions codegen/testserver/followschema/interfaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ func TestInterfaces(t *testing.T) {
`, &resp)

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)
require.Equal(t, float64(1), resp.Shapes[1].Coordinates.Y)
require.InEpsilon(t, float64(-1), resp.Shapes[0].Coordinates.X, 0.02)
require.InEpsilon(t, float64(0), resp.Shapes[0].Coordinates.Y, 0.02)
require.InEpsilon(t, float64(1), resp.Shapes[1].Coordinates.X, 0.02)
require.InEpsilon(t, float64(1), resp.Shapes[1].Coordinates.Y, 0.02)
StevenACoffman marked this conversation as resolved.
Show resolved Hide resolved
})

t.Run("fragment on interface must return merged fields", func(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions codegen/testserver/singlefile/interfaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ func TestInterfaces(t *testing.T) {
`, &resp)

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)
require.Equal(t, float64(1), resp.Shapes[1].Coordinates.Y)
require.InEpsilon(t, float64(-1), resp.Shapes[0].Coordinates.X, 0.02)
require.InEpsilon(t, float64(0), resp.Shapes[0].Coordinates.Y, 0.02)
require.InEpsilon(t, float64(1), resp.Shapes[1].Coordinates.X, 0.02)
require.InEpsilon(t, float64(1), resp.Shapes[1].Coordinates.Y, 0.02)
StevenACoffman marked this conversation as resolved.
Show resolved Hide resolved
})

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

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

func TestMarshalID(t *testing.T) {
Expand Down Expand Up @@ -130,7 +131,7 @@ func TestUnmarshalID(t *testing.T) {
if tt.ShouldError {
assert.Error(t, err)
} else {
assert.NoError(t, err)
require.NoError(t, err)
}
})
}
Expand All @@ -143,29 +144,29 @@ func TestMarshalUintID(t *testing.T) {
func TestUnMarshalUintID(t *testing.T) {
result, err := UnmarshalUintID("12")
assert.Equal(t, uint(12), result)
assert.NoError(t, err)
require.NoError(t, err)

result, err = UnmarshalUintID(12)
assert.Equal(t, uint(12), result)
assert.NoError(t, err)
require.NoError(t, err)

result, err = UnmarshalUintID(int64(12))
assert.Equal(t, uint(12), result)
assert.NoError(t, err)
require.NoError(t, err)

result, err = UnmarshalUintID(int32(12))
assert.Equal(t, uint(12), result)
assert.NoError(t, err)
require.NoError(t, err)

result, err = UnmarshalUintID(int(12))
assert.Equal(t, uint(12), result)
assert.NoError(t, err)
require.NoError(t, err)

result, err = UnmarshalUintID(uint32(12))
assert.Equal(t, uint(12), result)
assert.NoError(t, err)
require.NoError(t, err)

result, err = UnmarshalUintID(uint64(12))
assert.Equal(t, uint(12), result)
assert.NoError(t, err)
require.NoError(t, err)
}
11 changes: 6 additions & 5 deletions graphql/playground/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

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

func testResourceIntegrity(t *testing.T, handler func(title, endpoint string) http.HandlerFunc) {
Expand All @@ -19,13 +20,13 @@ func testResourceIntegrity(t *testing.T, handler func(title, endpoint string) ht
handler("example.org API", "/query").ServeHTTP(recorder, request)

res := recorder.Result()
defer assert.NoError(t, res.Body.Close())
defer require.NoError(t, res.Body.Close())

assert.Equal(t, http.StatusOK, res.StatusCode)
assert.True(t, strings.HasPrefix(res.Header.Get("Content-Type"), "text/html"))

doc, err := goquery.NewDocumentFromReader(res.Body)
assert.NoError(t, err)
require.NoError(t, err)
assert.NotNil(t, doc)

var baseUrl string
Expand Down Expand Up @@ -58,11 +59,11 @@ func assertNodesIntegrity(t *testing.T, baseUrl string, doc *goquery.Document, s

if len(url) != 0 && len(integrity) != 0 {
resp, err := http.Get(baseUrl + url)
assert.NoError(t, err)
require.NoError(t, err)
hasher := sha256.New()
_, err = io.Copy(hasher, resp.Body)
assert.NoError(t, err)
assert.NoError(t, resp.Body.Close())
require.NoError(t, err)
require.NoError(t, resp.Body.Close())
actual := "sha256-" + base64.StdEncoding.EncodeToString(hasher.Sum(nil))
assert.Equal(t, integrity, actual)
}
Expand Down
3 changes: 2 additions & 1 deletion plugin/federation/fieldset/fieldset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package fieldset
import (
"testing"

"github.com/99designs/gqlgen/codegen"
"github.com/stretchr/testify/require"
"github.com/vektah/gqlparser/v2/ast"

"github.com/99designs/gqlgen/codegen"
)

func TestUnnestedWithoutPrefix(t *testing.T) {
Expand Down