Skip to content

Commit d916819

Browse files
authored
Merge pull request #1427 from dolmen/fix-testify-usage
testing: fix usage of the Testify API
2 parents 2c5fa36 + 83d711d commit d916819

File tree

6 files changed

+111
-109
lines changed

6 files changed

+111
-109
lines changed

entry_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,20 +241,20 @@ func TestEntryWithIncorrectField(t *testing.T) {
241241
eWithFunc := e.WithFields(Fields{"func": fn})
242242
eWithFuncPtr := e.WithFields(Fields{"funcPtr": &fn})
243243

244-
assert.Equal(eWithFunc.err, `can not add field "func"`)
245-
assert.Equal(eWithFuncPtr.err, `can not add field "funcPtr"`)
244+
assert.Equal(`can not add field "func"`, eWithFunc.err)
245+
assert.Equal(`can not add field "funcPtr"`, eWithFuncPtr.err)
246246

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

250-
assert.Equal(eWithFunc.err, `can not add field "func"`)
251-
assert.Equal(eWithFuncPtr.err, `can not add field "funcPtr"`)
250+
assert.Equal(`can not add field "func"`, eWithFunc.err)
251+
assert.Equal(`can not add field "funcPtr"`, eWithFuncPtr.err)
252252

253253
eWithFunc = eWithFunc.WithTime(time.Now())
254254
eWithFuncPtr = eWithFuncPtr.WithTime(time.Now())
255255

256-
assert.Equal(eWithFunc.err, `can not add field "func"`)
257-
assert.Equal(eWithFuncPtr.err, `can not add field "funcPtr"`)
256+
assert.Equal(`can not add field "func"`, eWithFunc.err)
257+
assert.Equal(`can not add field "funcPtr"`, eWithFuncPtr.err)
258258
}
259259

260260
func TestEntryLogfLevel(t *testing.T) {

hook_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ func TestHookFires(t *testing.T) {
4141

4242
LogAndAssertJSON(t, func(log *Logger) {
4343
log.Hooks.Add(hook)
44-
assert.Equal(t, hook.Fired, false)
44+
assert.False(t, hook.Fired)
4545

4646
log.Print("test")
4747
}, func(fields Fields) {
48-
assert.Equal(t, hook.Fired, true)
48+
assert.True(t, hook.Fired)
4949
})
5050
}
5151

@@ -76,7 +76,7 @@ func TestHookCanModifyEntry(t *testing.T) {
7676
log.Hooks.Add(hook)
7777
log.WithField("wow", "elephant").Print("test")
7878
}, func(fields Fields) {
79-
assert.Equal(t, fields["wow"], "whale")
79+
assert.Equal(t, "whale", fields["wow"])
8080
})
8181
}
8282

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

9191
log.WithField("wow", "elephant").Print("test")
9292
}, func(fields Fields) {
93-
assert.Equal(t, fields["wow"], "whale")
94-
assert.Equal(t, hook2.Fired, true)
93+
assert.Equal(t, "whale", fields["wow"])
94+
assert.True(t, hook2.Fired)
9595
})
9696
}
9797

@@ -157,7 +157,7 @@ func TestErrorHookShouldntFireOnInfo(t *testing.T) {
157157
log.Hooks.Add(hook)
158158
log.Info("test")
159159
}, func(fields Fields) {
160-
assert.Equal(t, hook.Fired, false)
160+
assert.False(t, hook.Fired)
161161
})
162162
}
163163

@@ -168,7 +168,7 @@ func TestErrorHookShouldFireOnError(t *testing.T) {
168168
log.Hooks.Add(hook)
169169
log.Error("test")
170170
}, func(fields Fields) {
171-
assert.Equal(t, hook.Fired, true)
171+
assert.True(t, hook.Fired)
172172
})
173173
}
174174

hooks/writer/writer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ func TestDifferentLevelsGoToDifferentWriters(t *testing.T) {
3333
log.Warn("send to a")
3434
log.Info("send to b")
3535

36-
assert.Equal(t, a.String(), "level=warning msg=\"send to a\"\n")
37-
assert.Equal(t, b.String(), "level=info msg=\"send to b\"\n")
36+
assert.Equal(t, "level=warning msg=\"send to a\"\n", a.String())
37+
assert.Equal(t, "level=info msg=\"send to b\"\n", b.String())
3838
}

logger_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func TestWarninglnNotEqualToWarning(t *testing.T) {
7070

7171
type testBufferPool struct {
7272
buffers []*bytes.Buffer
73-
get int
73+
get int
7474
}
7575

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

9393
l.Info("test")
9494

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

0 commit comments

Comments
 (0)