Skip to content

Commit

Permalink
refactor(tests): use testify panic method instead of custom solution
Browse files Browse the repository at this point in the history
  • Loading branch information
ReneWerner87 committed Feb 28, 2024
1 parent ab2b0fc commit ac64308
Showing 1 changed file with 6 additions and 36 deletions.
42 changes: 6 additions & 36 deletions log/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,9 @@ func Test_DefaultLogger(t *testing.T) {
Warn("work may fail")
Error("work failed")

didPanic := false
func() {
defer func() {
if r := recover(); r != nil {
didPanic = true
}
}()
require.Panics(t, func() {
Panic("work panic")
}()

if !didPanic {
t.Errorf("Expected a panic when the panic logger method is called")
}
})

require.Equal(t, "[Trace] trace work\n"+
"[Debug] received work order\n"+
Expand All @@ -90,19 +80,9 @@ func Test_DefaultFormatLogger(t *testing.T) {
Warnf("%s may fail", work)
Errorf("%s failed", work)

didPanic := false
func() {
defer func() {
if r := recover(); r != nil {
didPanic = true
}
}()
require.Panics(t, func() {
Panicf("%s panic", work)
}()

if !didPanic {
t.Errorf("Expected a panic when the panic logger method is called")
}
})

require.Equal(t, "[Trace] trace work\n"+
"[Debug] received work order\n"+
Expand All @@ -126,19 +106,9 @@ func Test_CtxLogger(t *testing.T) {
WithContext(ctx).Warnf("%s may fail", work)
WithContext(ctx).Errorf("%s failed %d", work, 50)

didPanic := false
func() {
defer func() {
if r := recover(); r != nil {
didPanic = true
}
}()
require.Panics(t, func() {
WithContext(ctx).Panicf("%s panic", work)
}()

if !didPanic {
t.Errorf("Expected a panic when the panic logger method is called")
}
})

require.Equal(t, "[Trace] trace work\n"+
"[Debug] received work order\n"+
Expand Down

0 comments on commit ac64308

Please sign in to comment.