Skip to content

Commit

Permalink
refactor: simplify test asserts (#3061)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear committed May 9, 2024
1 parent 7421bdf commit 39d3d8d
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ linters-settings:
disable-all: true
enable:
- bool-compare
- compares
- error-is-as
- error-nil
- expected-actual
- nil-compare

linters:
disable-all: true
Expand Down
5 changes: 2 additions & 3 deletions codegen/config/config_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package config

import (
"errors"
"io/fs"
"os"
"path/filepath"
Expand Down Expand Up @@ -103,7 +102,7 @@ func TestLoadConfigFromDefaultLocation(t *testing.T) {
require.NoError(t, err)

cfg, err = LoadConfigFromDefaultLocations()
require.True(t, errors.Is(err, fs.ErrNotExist))
require.ErrorIs(t, err, fs.ErrNotExist)
})
}

Expand All @@ -126,7 +125,7 @@ func TestLoadDefaultConfig(t *testing.T) {
require.NoError(t, err)

cfg, err = LoadDefaultConfig()
require.True(t, errors.Is(err, fs.ErrNotExist))
require.ErrorIs(t, err, fs.ErrNotExist)
})
}

Expand Down
4 changes: 2 additions & 2 deletions codegen/testserver/followschema/directive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ func TestDirectives(t *testing.T) {

require.NoError(t, err)
require.Equal(t, "Ok", resp.DirectiveObject.Text)
require.True(t, resp.DirectiveObject.NullableText == nil)
require.Nil(t, resp.DirectiveObject.NullableText)
require.Equal(t, "Query_field", resp.DirectiveObject.Order[0])
require.Equal(t, "order2_1", resp.DirectiveObject.Order[1])
require.Equal(t, "order1_2", resp.DirectiveObject.Order[2])
Expand All @@ -405,7 +405,7 @@ func TestDirectives(t *testing.T) {
err := c.Post(`query { directiveObjectWithCustomGoModel{ nullableText } }`, &resp)

require.NoError(t, err)
require.True(t, resp.DirectiveObjectWithCustomGoModel.NullableText == nil)
require.Nil(t, resp.DirectiveObjectWithCustomGoModel.NullableText)
})
})

Expand Down
2 changes: 1 addition & 1 deletion codegen/testserver/followschema/useptr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ import (
func TestUserPtr(t *testing.T) {
s := &Stub{}
r := reflect.TypeOf(s.QueryResolver.OptionalUnion)
require.True(t, r.Out(0).Kind() == reflect.Interface)
require.Equal(t, reflect.Interface, r.Out(0).Kind())
}
4 changes: 2 additions & 2 deletions codegen/testserver/singlefile/directive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ func TestDirectives(t *testing.T) {

require.NoError(t, err)
require.Equal(t, "Ok", resp.DirectiveObject.Text)
require.True(t, resp.DirectiveObject.NullableText == nil)
require.Nil(t, resp.DirectiveObject.NullableText)
require.Equal(t, "Query_field", resp.DirectiveObject.Order[0])
require.Equal(t, "order2_1", resp.DirectiveObject.Order[1])
require.Equal(t, "order1_2", resp.DirectiveObject.Order[2])
Expand All @@ -405,7 +405,7 @@ func TestDirectives(t *testing.T) {
err := c.Post(`query { directiveObjectWithCustomGoModel{ nullableText } }`, &resp)

require.NoError(t, err)
require.True(t, resp.DirectiveObjectWithCustomGoModel.NullableText == nil)
require.Nil(t, resp.DirectiveObjectWithCustomGoModel.NullableText)
})
})

Expand Down
2 changes: 1 addition & 1 deletion codegen/testserver/singlefile/useptr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ import (
func TestUserPtr(t *testing.T) {
s := &Stub{}
r := reflect.TypeOf(s.QueryResolver.OptionalUnion)
require.True(t, r.Out(0).Kind() == reflect.Interface)
require.Equal(t, reflect.Interface, r.Out(0).Kind())
}
6 changes: 3 additions & 3 deletions plugin/modelgen/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestModelGeneration(t *testing.T) {
for _, commentGroup := range node.Comments {
text := commentGroup.Text()
words := strings.Split(text, " ")
require.True(t, len(words) > 1, "expected description %q to have more than one word", text)
require.Greaterf(t, len(words), 1, "expected description %q to have more than one word", text)
}
})

Expand All @@ -81,7 +81,7 @@ func TestModelGeneration(t *testing.T) {
}

for _, tag := range expectedTags {
require.True(t, strings.Contains(fileText, tag), "\nexpected:\n"+tag+"\ngot\n"+fileText)
require.Contains(t, fileText, tag, "\nexpected:\n"+tag+"\ngot\n"+fileText)
}
})

Expand All @@ -99,7 +99,7 @@ func TestModelGeneration(t *testing.T) {
}

for _, tag := range expectedTags {
require.True(t, strings.Contains(fileText, tag), "\nexpected:\n"+tag+"\ngot\n"+fileText)
require.Contains(t, fileText, tag, "\nexpected:\n"+tag+"\ngot\n"+fileText)
}
})

Expand Down

0 comments on commit 39d3d8d

Please sign in to comment.