Skip to content

Commit

Permalink
Merge pull request #831 from alexandear/refactor/test-asserts
Browse files Browse the repository at this point in the history
Refactor test asserts
  • Loading branch information
LandonTClipp authored Oct 22, 2024
2 parents 146f48b + f66028a commit f9da2b6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
8 changes: 8 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,16 @@ linters:
- prealloc
- predeclared
- reassign
- testifylint
linters-settings:
staticcheck:
checks:
- all
- '-SA1024'
testifylint:
disable-all: true
enable:
- compares
- empty
- expected-actual
- len
4 changes: 2 additions & 2 deletions pkg/fixtures/test/expecter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestExpecter(t *testing.T) {
require.NoError(t, expMock.Variadic(1, 2, 3, 4))
require.NoError(t, expMock.Variadic(2, 3, 4))
require.NoError(t, expMock.Variadic(args...))
require.Equal(t, runCalled, 5)
require.Equal(t, 5, runCalled)
expMock.AssertExpectations(t)
})

Expand Down Expand Up @@ -175,7 +175,7 @@ func TestExpecter(t *testing.T) {
}).Return(nil).Once()
require.NoError(t, expMock.VariadicMany(defaultInt, defaultString, args...))

require.Equal(t, runCalled, 5)
require.Equal(t, 5, runCalled)
expMock.AssertExpectations(t)
})

Expand Down
7 changes: 3 additions & 4 deletions pkg/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestBuildTagInFilename(t *testing.T) {
assert.NoError(t, err) // Expect "redeclared in this block" if tags aren't respected

nodes := parser.Interfaces()
assert.Equal(t, 1, len(nodes))
require.Len(t, nodes, 1)
assert.Equal(t, "IfaceWithBuildTagInFilename", nodes[0].Name)
}

Expand All @@ -64,7 +64,7 @@ func TestBuildTagInComment(t *testing.T) {
assert.NoError(t, err) // Expect "redeclared in this block" if tags aren't respected

nodes := parser.Interfaces()
assert.Equal(t, 1, len(nodes))
require.Len(t, nodes, 1)
assert.Equal(t, "IfaceWithBuildTagInComment", nodes[0].Name)
}

Expand Down Expand Up @@ -94,6 +94,5 @@ func TestCustomBuildTag(t *testing.T) {
func TestParsePackages(t *testing.T) {
parser := NewParser([]string{})
require.NoError(t, parser.ParsePackages(context.Background(), []string{"github.com/vektra/mockery/v2/pkg/fixtures"}))
assert.NotEqual(t, 0, len(parser.files))

assert.NotEmpty(t, parser.files)
}
4 changes: 2 additions & 2 deletions pkg/walker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestWalkerHere(t *testing.T) {

w.Walk(context.Background(), gv)

assert.True(t, len(gv.Interfaces) > 10)
assert.Greater(t, len(gv.Interfaces), 10)
first := gv.Interfaces[0]
assert.Equal(t, "A", first.Name)
assert.Equal(t, getFixturePath("struct_value.go"), first.FileName)
Expand All @@ -88,7 +88,7 @@ func TestWalkerRegexp(t *testing.T) {

w.Walk(context.Background(), gv)

assert.True(t, len(gv.Interfaces) >= 1)
assert.GreaterOrEqual(t, len(gv.Interfaces), 1)
first := gv.Interfaces[0]
assert.Equal(t, "AsyncProducer", first.Name)
assert.Equal(t, getFixturePath("async.go"), first.FileName)
Expand Down

0 comments on commit f9da2b6

Please sign in to comment.