Skip to content

Commit

Permalink
feat: panic on error log feature
Browse files Browse the repository at this point in the history
  • Loading branch information
shoriwe committed Apr 26, 2023
1 parent 5fdf6cf commit 508ea9a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions common/logs/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ func LogOnError(err error) {
log.Print(err)
}
}

func PanicOnError(err error) {
if err != nil {
panic(err)
}
}
14 changes: 14 additions & 0 deletions common/logs/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package logs
import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
)

func TestLogOnError(t *testing.T) {
Expand All @@ -13,3 +15,15 @@ func TestLogOnError(t *testing.T) {
LogOnError(fmt.Errorf("an error"))
})
}

func TestPanicOnError(t *testing.T) {
t.Run("Nil", func(tt *testing.T) {
PanicOnError(nil)
})
t.Run("Error", func(tt *testing.T) {
defer func(ttt *testing.T) {
assert.NotNil(ttt, recover())
}(tt)
PanicOnError(fmt.Errorf("an error"))
})
}

0 comments on commit 508ea9a

Please sign in to comment.