Skip to content

Commit

Permalink
ci: update golangci-lint configuration (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
reugn authored Sep 28, 2024
1 parent c4375d5 commit e042b54
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 36 deletions.
20 changes: 17 additions & 3 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,27 @@ on:
- master
pull_request:

permissions:
contents: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: golangci-lint
uses: golangci/golangci-lint-action@v4

- name: Get go version from go.mod
run: |
echo "GO_VERSION=$(grep '^go ' go.mod | cut -d " " -f 2)" >> $GITHUB_ENV
- name: Setup-go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.61.0
11 changes: 9 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
run:
timeout: 1m
timeout: 2m

linters:
disable-all: true
Expand All @@ -8,32 +8,39 @@ linters:
- errcheck
- errname
- errorlint
- exportloopref
- funlen
- gci
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- gosec
- gosimple
- govet
- ineffassign
- lll
- misspell
- nolintlint
- prealloc
- revive
- staticcheck
- stylecheck
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
- whitespace

linters-settings:
errcheck:
exclude-functions:
- (*log.Logger).Output
thelper:
test:
begin: false

issues:
exclude-rules:
Expand Down
1 change: 1 addition & 0 deletions job/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/reugn/go-quartz/job"
)

//nolint:gosec
func TestMultipleExecution(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
Expand Down
66 changes: 35 additions & 31 deletions logger/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@ func TestSimpleLogger(t *testing.T) {
logger.SetDefault(logger.NewSimpleLogger(stdLogger, logger.LevelInfo))

logger.Trace("Trace")
assertEmpty(&b, t)
assertEmpty(t, &b)
logger.Tracef("Trace%s", "f")
assertEmpty(&b, t)
assertEmpty(t, &b)

logger.Debug("Debug")
assertEmpty(&b, t)
assertEmpty(t, &b)
logger.Debugf("Debug%s", "f")
assertEmpty(&b, t)
assertEmpty(t, &b)

logger.Info("Info")
assertNotEmpty(&b, t)
assertNotEmpty(t, &b)
logger.Infof("Info%s", "f")
assertNotEmpty(&b, t)
assertNotEmpty(t, &b)

logger.Warn("Warn")
assertNotEmpty(&b, t)
assertNotEmpty(t, &b)
logger.Warnf("Warn%s", "f")
assertNotEmpty(&b, t)
assertNotEmpty(t, &b)

logger.Error("Error")
assertNotEmpty(&b, t)
assertNotEmpty(t, &b)
logger.Errorf("Error%s", "f")
assertNotEmpty(&b, t)
assertNotEmpty(t, &b)
}

func TestLoggerOff(t *testing.T) {
Expand All @@ -51,9 +51,9 @@ func TestLoggerOff(t *testing.T) {
t.Fatal("logger.LevelError is enabled")
}
logger.Error("Error")
assertEmpty(&b, t)
assertEmpty(t, &b)
logger.Errorf("Error%s", "f")
assertEmpty(&b, t)
assertEmpty(t, &b)
}

func TestLoggerRace(t *testing.T) {
Expand Down Expand Up @@ -103,57 +103,61 @@ func TestLogFormat(t *testing.T) {

empty := struct{}{}
logr.Trace("Trace")
assertNotEmpty(&b, t)
assertNotEmpty(t, &b)
logr.Tracef("Tracef: %s, %d, %v, %v", "a", 1, true, empty)
checkLogFormat(&b, t)
checkLogFormat(t, &b)
logger.Tracef("Tracef: %s, %d, %v, %v", "a", 1, true, empty)
checkLogFormat(&b, t)
checkLogFormat(t, &b)

logr.Debug("Debug")
assertNotEmpty(&b, t)
assertNotEmpty(t, &b)
logr.Debugf("Debugf: %s, %d, %v, %v", "a", 1, true, empty)
checkLogFormat(&b, t)
checkLogFormat(t, &b)
logger.Debugf("Debugf: %s, %d, %v, %v", "a", 1, true, empty)
checkLogFormat(&b, t)
checkLogFormat(t, &b)

logr.Infof("Infof: %s, %d, %v, %v", "a", 1, true, empty)
checkLogFormat(&b, t)
checkLogFormat(t, &b)
logger.Infof("Infof: %s, %d, %v, %v", "a", 1, true, empty)
checkLogFormat(&b, t)
checkLogFormat(t, &b)

logr.Warnf("Warnf: %s, %d, %v, %v", "a", 1, true, empty)
checkLogFormat(&b, t)
checkLogFormat(t, &b)
logger.Warnf("Warnf: %s, %d, %v, %v", "a", 1, true, empty)
checkLogFormat(&b, t)
checkLogFormat(t, &b)

logr.Errorf("Errorf: %s, %d, %v, %v", "a", 1, true, empty)
checkLogFormat(&b, t)
checkLogFormat(t, &b)
logger.Errorf("Errorf: %s, %d, %v, %v", "a", 1, true, empty)
checkLogFormat(&b, t)
checkLogFormat(t, &b)
}

func assertEmpty(r io.Reader, t *testing.T) {
logMsg := readAll(r, t)
func assertEmpty(t *testing.T, r io.Reader) {
t.Helper()
logMsg := readAll(t, r)
if logMsg != "" {
t.Fatalf("log msg is not empty: %s", logMsg)
}
}

func assertNotEmpty(r io.Reader, t *testing.T) {
logMsg := readAll(r, t)
func assertNotEmpty(t *testing.T, r io.Reader) {
t.Helper()
logMsg := readAll(t, r)
if logMsg == "" {
t.Fatal("log msg is empty")
}
}

func checkLogFormat(r io.Reader, t *testing.T) {
logMsg := readAll(r, t)
func checkLogFormat(t *testing.T, r io.Reader) {
t.Helper()
logMsg := readAll(t, r)
if !strings.Contains(logMsg, "a, 1, true, {}") {
t.Fatalf("invalid log format: %s", logMsg)
}
}

func readAll(r io.Reader, t *testing.T) string {
func readAll(t *testing.T, r io.Reader) string {
t.Helper()
bytes, err := io.ReadAll(r)
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit e042b54

Please sign in to comment.