diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d1f081f..d1ed3ed 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,7 +1,7 @@ name: Test -on: +on: push: - branches: [ main ] + branches: [main] pull_request: jobs: @@ -13,8 +13,12 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version: '1.21.3' + go-version: "1.21.3" - name: Install dependencies run: go get . - - name: Test with the Go CLI + - name: Lint + uses: golangci/golangci-lint-action@v6 + with: + version: v1.60 + - name: Test run: go test ./... diff --git a/internal/cli/utils_test.go b/internal/cli/utils_test.go index b8be3e2..8311c4e 100644 --- a/internal/cli/utils_test.go +++ b/internal/cli/utils_test.go @@ -17,7 +17,7 @@ func TestCombineBeforeFuncs(t *testing.T) { before_func := CombineBeforeFuncs(mockBeforeFuncs.Func1, mockBeforeFuncs.Func2) - before_func(nil) + _ = before_func(nil) mockBeforeFuncs.AssertExpectations(t) } @@ -47,7 +47,7 @@ func TestConfigureLogs(t *testing.T) { flag.Bool("verbose", input, "") context := cli.NewContext(nil, flag, nil) - ConfigureLogs(context) + _ = ConfigureLogs(context) assert.Equal(t, zerolog.GlobalLevel(), want) } @@ -69,10 +69,10 @@ func TestConfigFileLoaderNoFile(t *testing.T) { func TestLogArguments(t *testing.T) { flag := flag.NewFlagSet("flag", flag.ContinueOnError) flag.String("some-flag", "", "") - flag.Set("some-flag", "value") + _ = flag.Set("some-flag", "value") context := cli.NewContext(nil, flag, nil) - LogArguments(context) + _ = LogArguments(context) // How to assert that the log message was correct? } diff --git a/internal/gitlab/gitlab_test.go b/internal/gitlab/gitlab_test.go index 25407df..07795c2 100644 --- a/internal/gitlab/gitlab_test.go +++ b/internal/gitlab/gitlab_test.go @@ -230,7 +230,7 @@ func (c *mockClient) ListProjectIssues(projectId interface{}, opt *gitlab.ListPr args := c.Called(projectId, opt, options) var r *gitlab.Response if resp := args.Get(1); resp != nil { - resp = args.Get(1).(*gitlab.Response) + r = args.Get(1).(*gitlab.Response) } return args.Get(0).([]*gitlab.Issue), r, args.Error(2) } diff --git a/internal/publish/to_gitlab_test.go b/internal/publish/to_gitlab_test.go index 87b7b33..ebafe09 100644 --- a/internal/publish/to_gitlab_test.go +++ b/internal/publish/to_gitlab_test.go @@ -176,7 +176,7 @@ func TestPublishAsGitlabIssues(t *testing.T) { }, } - PublishAsGitlabIssues(reports, mockGitlabService) + _ = PublishAsGitlabIssues(reports, mockGitlabService) mockGitlabService.AssertExpectations(t) t.Run("FillsTheIssueUrl", func(t *testing.T) { diff --git a/internal/publish/to_slack_test.go b/internal/publish/to_slack_test.go index 5b6f31e..73eec20 100644 --- a/internal/publish/to_slack_test.go +++ b/internal/publish/to_slack_test.go @@ -43,7 +43,7 @@ func TestPublishAsSpecificChannelSlackMessage(t *testing.T) { ProjectConfig: scanner.ProjectConfig{SlackChannel: "channel"}, } - PublishAsSpecificChannelSlackMessage([]scanner.Report{report}, mockSlackService) + _ = PublishAsSpecificChannelSlackMessage([]scanner.Report{report}, mockSlackService) mockSlackService.AssertExpectations(t) mockSlackService.AssertNumberOfCalls(t, "PostMessage", 1) diff --git a/internal/shell/shell.go b/internal/shell/shell.go index 14a5c00..ac82a7d 100644 --- a/internal/shell/shell.go +++ b/internal/shell/shell.go @@ -39,7 +39,8 @@ func (c *shellCommandRunner) Run(in CommandInput) (CommandOutput, error) { if in.Timeout == 0 { in.Timeout = defaultTimeout } - ctx, _ := context.WithTimeout(context.Background(), in.Timeout) + ctx, cancel := context.WithTimeout(context.Background(), in.Timeout) + defer cancel() cmd := exec.CommandContext(ctx, in.Name, in.Args...) out, err := cmd.Output() diff --git a/justfile b/justfile index 10d4841..e5bda49 100644 --- a/justfile +++ b/justfile @@ -5,5 +5,8 @@ run *ARGS: GITLAB_TOKEN=$GITLAB_TOKEN go run . {{ARGS}} alias t := test -test: - go test ./... +test *ARGS="./...": + go test {{ARGS}} + +lint: + golangci-lint run ./...