Skip to content

Commit

Permalink
testing: fix usage of the Testify API
Browse files Browse the repository at this point in the history
Fix incorrect usages of the Testify API, thanks to testifylint.

Note: I'm a Testify co-maintainer
  • Loading branch information
dolmen committed Mar 12, 2024
1 parent dd1b4c2 commit 1718cbc
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 109 deletions.
12 changes: 6 additions & 6 deletions entry_test.go
Expand Up @@ -241,20 +241,20 @@ func TestEntryWithIncorrectField(t *testing.T) {
eWithFunc := e.WithFields(Fields{"func": fn})
eWithFuncPtr := e.WithFields(Fields{"funcPtr": &fn})

assert.Equal(eWithFunc.err, `can not add field "func"`)
assert.Equal(eWithFuncPtr.err, `can not add field "funcPtr"`)
assert.Equal(`can not add field "func"`, eWithFunc.err)
assert.Equal(`can not add field "funcPtr"`, eWithFuncPtr.err)

eWithFunc = eWithFunc.WithField("not_a_func", "it is a string")
eWithFuncPtr = eWithFuncPtr.WithField("not_a_func", "it is a string")

assert.Equal(eWithFunc.err, `can not add field "func"`)
assert.Equal(eWithFuncPtr.err, `can not add field "funcPtr"`)
assert.Equal(`can not add field "func"`, eWithFunc.err)
assert.Equal(`can not add field "funcPtr"`, eWithFuncPtr.err)

eWithFunc = eWithFunc.WithTime(time.Now())
eWithFuncPtr = eWithFuncPtr.WithTime(time.Now())

assert.Equal(eWithFunc.err, `can not add field "func"`)
assert.Equal(eWithFuncPtr.err, `can not add field "funcPtr"`)
assert.Equal(`can not add field "func"`, eWithFunc.err)
assert.Equal(`can not add field "funcPtr"`, eWithFuncPtr.err)
}

func TestEntryLogfLevel(t *testing.T) {
Expand Down
14 changes: 7 additions & 7 deletions hook_test.go
Expand Up @@ -41,11 +41,11 @@ func TestHookFires(t *testing.T) {

LogAndAssertJSON(t, func(log *Logger) {
log.Hooks.Add(hook)
assert.Equal(t, hook.Fired, false)
assert.False(t, hook.Fired)

log.Print("test")
}, func(fields Fields) {
assert.Equal(t, hook.Fired, true)
assert.True(t, hook.Fired)
})
}

Expand Down Expand Up @@ -76,7 +76,7 @@ func TestHookCanModifyEntry(t *testing.T) {
log.Hooks.Add(hook)
log.WithField("wow", "elephant").Print("test")
}, func(fields Fields) {
assert.Equal(t, fields["wow"], "whale")
assert.Equal(t, "whale", fields["wow"])
})
}

Expand All @@ -90,8 +90,8 @@ func TestCanFireMultipleHooks(t *testing.T) {

log.WithField("wow", "elephant").Print("test")
}, func(fields Fields) {
assert.Equal(t, fields["wow"], "whale")
assert.Equal(t, hook2.Fired, true)
assert.Equal(t, "whale", fields["wow"])
assert.True(t, hook2.Fired)
})
}

Expand Down Expand Up @@ -157,7 +157,7 @@ func TestErrorHookShouldntFireOnInfo(t *testing.T) {
log.Hooks.Add(hook)
log.Info("test")
}, func(fields Fields) {
assert.Equal(t, hook.Fired, false)
assert.False(t, hook.Fired)
})
}

Expand All @@ -168,7 +168,7 @@ func TestErrorHookShouldFireOnError(t *testing.T) {
log.Hooks.Add(hook)
log.Error("test")
}, func(fields Fields) {
assert.Equal(t, hook.Fired, true)
assert.True(t, hook.Fired)
})
}

Expand Down
4 changes: 2 additions & 2 deletions hooks/writer/writer_test.go
Expand Up @@ -33,6 +33,6 @@ func TestDifferentLevelsGoToDifferentWriters(t *testing.T) {
log.Warn("send to a")
log.Info("send to b")

assert.Equal(t, a.String(), "level=warning msg=\"send to a\"\n")
assert.Equal(t, b.String(), "level=info msg=\"send to b\"\n")
assert.Equal(t, "level=warning msg=\"send to a\"\n", a.String())
assert.Equal(t, "level=info msg=\"send to b\"\n", b.String())
}
4 changes: 2 additions & 2 deletions logger_test.go
Expand Up @@ -70,7 +70,7 @@ func TestWarninglnNotEqualToWarning(t *testing.T) {

type testBufferPool struct {
buffers []*bytes.Buffer
get int
get int
}

func (p *testBufferPool) Get() *bytes.Buffer {
Expand All @@ -92,6 +92,6 @@ func TestLogger_SetBufferPool(t *testing.T) {

l.Info("test")

assert.Equal(t, pool.get, 1, "Logger.SetBufferPool(): The BufferPool.Get() must be called")
assert.Equal(t, 1, pool.get, "Logger.SetBufferPool(): The BufferPool.Get() must be called")
assert.Len(t, pool.buffers, 1, "Logger.SetBufferPool(): The BufferPool.Put() must be called")
}

0 comments on commit 1718cbc

Please sign in to comment.