Skip to content

Commit

Permalink
Merge pull request #17 from seipan/feat/golang-ci-lint-reviewdog
Browse files Browse the repository at this point in the history
feat(ci) : add golangci-lint
  • Loading branch information
seipan committed Sep 15, 2023
2 parents eb14ccf + 9596d21 commit f53ffb6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
build:
strategy:
matrix:
go-version: ['1.18', '1.19', '1.20']
go-version: ['1.18', '1.19', '1.20', '1.21']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -34,3 +34,6 @@ jobs:
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

- name: golangci-lint
uses: reviewdog/action-golangci-lint@v2
4 changes: 0 additions & 4 deletions level.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ const (
PanicLevel
// FatalLevel logs a message, then calls os.Exit(1).
FatalLevel

// In this logger, the lowest log level is Debug level and the highest level is Fatal Level
_minLevel = DebugLevel
_maxLevel = FatalLevel
)

// Converts log level to string, returns unknown if log level is not expected.
Expand Down
45 changes: 35 additions & 10 deletions level_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@

package loghook

import "testing"
import (
"testing"

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

func TestString(t *testing.T) {
tests := []struct {
Expand All @@ -46,9 +50,7 @@ func TestString(t *testing.T) {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if tt.reqmessage != tt.level.String() {
t.Error("level to string err")
}
assert.Equal(t, tt.reqmessage, tt.level.String())
})
}
}
Expand Down Expand Up @@ -76,12 +78,35 @@ func TestParseLevel(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
res, err := ParseLevel(tt.reqstr)
if err != nil {
t.Error(err)
}
if tt.reqlvl != res {
t.Errorf("parse level err want %v, got %v", tt.reqlvl, res)
}
assert.NoError(t, err)
assert.Equal(t, tt.reqlvl, res)
})
}
}

func TestMarshalText(t *testing.T) {
tests := []struct {
name string
reqlvl Level
reqstr string
}{
{
name: "success info level",
reqlvl: InfoLevel,
reqstr: "info",
},
{
name: "success error level",
reqlvl: ErrorLevel,
reqstr: "error",
},
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
res := tt.reqlvl.MarshalText()
assert.Equal(t, tt.reqstr, res)
})
}
}

0 comments on commit f53ffb6

Please sign in to comment.