diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..6b079e6 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,36 @@ +--- +linters: + enable: + - errname + - errorlint + - exhaustive + - gofumpt + - goimports + - goprintffuncname + - misspell + - gomnd + - tagliatelle + - tenv + - testpackage + - thelper + - tparallel + - unconvert + - wrapcheck + - wsl + disable: + - gochecknoglobals + +linters-settings: + gosec: + excludes: + - G204 + tagliatelle: + case: + rules: + yaml: snake + +issues: + exclude-rules: + - path: _test\.go + linters: + - gosec diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fdc801b..09d54dc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,11 +7,9 @@ repos: - id: trailing-whitespace - id: end-of-file-fixer - id: check-merge-conflict - - repo: https://github.com/dnephin/pre-commit-golang - rev: v0.5.1 + - repo: https://github.com/golangci/golangci-lint + rev: v1.52.2 hooks: - - id: go-fmt - - id: go-imports - id: golangci-lint - repo: https://github.com/IamTheFij/docker-pre-commit rev: v3.0.1 diff --git a/itest/docker-compose.yml b/itest/docker-compose.yml index e96b252..2bee388 100644 --- a/itest/docker-compose.yml +++ b/itest/docker-compose.yml @@ -9,6 +9,8 @@ services: command: ["-watch", "10s", "-debug"] volumes: - /var/run/docker.sock:/var/run/docker.sock:ro + environment: + DOCKER_API_VERSION: 1.45 start_echoer: image: busybox:latest diff --git a/main_test.go b/main_test.go index 7aceb0f..3a498e0 100644 --- a/main_test.go +++ b/main_test.go @@ -51,6 +51,8 @@ type FakeDockerClient struct { // AssertFakeCalls checks expected against actual calls to fake methods func (fakeClient FakeDockerClient) AssertFakeCalls(t *testing.T, expectedCalls map[string][]FakeCall, message string) { + t.Helper() + if !reflect.DeepEqual(fakeClient.FakeCalls, expectedCalls) { t.Errorf( "%s: Expected and actual calls do not match. Expected %+v Actual %+v", @@ -161,6 +163,8 @@ func NewFakeDockerClient() *FakeDockerClient { // ErrorUnequal checks that two values are equal and fails the test if not func ErrorUnequal(t *testing.T, expected interface{}, actual interface{}, message string) { + t.Helper() + if expected != actual { t.Errorf("%s Expected: %+v Actual: %+v", message, expected, actual) } @@ -345,6 +349,7 @@ func TestQueryScheduledJobs(t *testing.T) { t.Logf("Expected jobs: %+v, Actual jobs: %+v", c.expectedJobs, jobs) ErrorUnequal(t, len(c.expectedJobs), len(jobs), "Job lengths don't match") + for i, job := range jobs { ErrorUnequal(t, c.expectedJobs[i], job, "Job value does not match") } @@ -453,6 +458,7 @@ func TestScheduleJobs(t *testing.T) { t.Logf("Cron entries: %+v", scheduledEntries) ErrorUnequal(t, len(c.expectedJobs), len(scheduledEntries), "Job and entry lengths don't match") + for i, entry := range scheduledEntries { ErrorUnequal(t, c.expectedJobs[i], entry.Job, "Job value does not match entry") } @@ -659,6 +665,7 @@ func TestDoLoop(t *testing.T) { t.Logf("Cron entries: %+v", scheduledEntries) ErrorUnequal(t, len(c.expectedJobs), len(scheduledEntries), "Job and entry lengths don't match") + for i, entry := range scheduledEntries { ErrorUnequal(t, c.expectedJobs[i], entry.Job, "Job value does not match entry") } @@ -890,9 +897,11 @@ func TestRunExecJobs(t *testing.T) { t.Log("Recovered from panic") t.Log(err) } + c.client.AssertFakeCalls(t, c.expectedCalls, "Failed") }() job.Run() + if c.expectPanic { t.Errorf("Expected panic but got none") } @@ -1006,9 +1015,11 @@ func TestRunStartJobs(t *testing.T) { defer func() { // Recover from panics, if there were any _ = recover() + c.client.AssertFakeCalls(t, c.expectedCalls, "Failed") }() job.Run() + if c.expectPanic { t.Errorf("Expected panic but got none") }