diff --git a/.github/matchers/golangci-lint.json b/.github/matchers/golangci-lint.json new file mode 100644 index 0000000..0c4c5a6 --- /dev/null +++ b/.github/matchers/golangci-lint.json @@ -0,0 +1,15 @@ +{ + "problemMatcher": [ + { + "owner": "golangci-lint", + "pattern": { + "regexp": "^(.+\\.go):(\\d+):(\\d+): \\w+: (.+) \\((\\w+)\\)$", + "file": 1, + "line": 2, + "column": 3, + "message": 4, + "code": 5 + } + } + ] +} diff --git a/.github/matchers/testify.json b/.github/matchers/testify.json new file mode 100644 index 0000000..7d9a04b --- /dev/null +++ b/.github/matchers/testify.json @@ -0,0 +1,18 @@ +{ + "problemMatcher": [ + { + "owner": "github.com/stretchr/testify/assert", + "pattern": [ + { + "regexp": "^\\s+Error Trace:\\s+(.+):(\\d+)$", + "file": 1, + "line": 2 + }, + { + "regexp": "^\\s+Error:\\s+(.+)(?=:?)", + "message": 1 + } + ] + } + ] +} diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b5c2ebc..0bfb386 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -19,6 +19,8 @@ jobs: with: go-version-file: go.mod - run: go version + - run: echo "::add-matcher::.github/matchers/golangci-lint.json" + - run: make lint test: @@ -32,6 +34,8 @@ jobs: with: go-version-file: go.mod - run: go version + - run: echo "::add-matcher::.github/matchers/testify.json" + - run: make test - name: Upload coverage reports to Codecov if: success() diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..78111af --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,8 @@ +{ + "recommendations": [ + "editorconfig.editorconfig", + "github.vscode-github-actions", + "github.vscode-pull-request-github", + "golang.go" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e0a47e8 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,10 @@ +{ + "task.allowAutomaticTasks": "off", + "window.title": "go.strv.io/background${separator}${activeEditorShort}", + "go.lintTool": "golangci-lint", + "go.testTimeout": "5s", + "go.useLanguageServer": true, + "gopls": { + "ui.semanticTokens": true, + }, +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..ccfe825 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,101 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "make: test", + "detail": "Run the test suite", + "type": "process", + "command": "make", + "args": [ + "test" + ], + "problemMatcher": { + "owner": "github.com/stretchr/testify/assert", + "applyTo": "allDocuments", + "fileLocation": [ + "absolute" + ], + "pattern": [ + { + "regexp": "^\\s+Error Trace:\\s+(.+):(\\d+)$", + "file": 1, + "line": 2 + }, + // This is extremely rudimentary because VS Code does not support matching the message across multiple lines + // so this only shows the error but does not show the expected and actual values in the UI 🤦‍♂️ + { + "regexp": "^\\s+Error:\\s+(.+)(?=:?)", + "message": 1 + } + ] + }, + "isTestCommand": true, + "group": { + "kind": "test", + "isDefault": true + }, + "presentation": { + "clear": true + }, + "icon": { + "id": "beaker", + "color": "terminal.ansiGreen" + } + }, + { + "label": "make: lint", + "detail": "Run the linter using Docker (golangci-lint)", + "type": "process", + "command": "make", + "args": [ + "lint" + ], + "problemMatcher": { + "owner": "golangci-lint", + "applyTo": "allDocuments", + "fileLocation": [ + "relative", + "${workspaceFolder}" + ], + "pattern": { + "regexp": "^(.+\\.go):(\\d+):(\\d+): \\w+: (.+) \\((\\w+)\\)$", + "file": 1, + "line": 2, + "column": 3, + "message": 4, + "code": 5 + }, + }, + "group": { + "kind": "test", + "isDefault": false + }, + "presentation": { + "clear": true, + }, + "icon": { + "id": "eye", + "color": "terminal.ansiYellow" + } + }, + { + "label": "make: clean", + "detail": "Remove compiled and generated files or caches", + "type": "process", + "command": "make", + "args": [ + "clean" + ], + "problemMatcher": [], + "presentation": { + "showReuseMessage": false, + "clear": true, + "close": true + }, + "icon": { + "id": "trash", + "color": "terminal.ansiRed" + } + } + ], +} diff --git a/background.go b/background.go index f18944f..0391197 100644 --- a/background.go +++ b/background.go @@ -99,12 +99,11 @@ func (m *Manager) Cancel() { // Close is a convenience method that calls Wait() and Cancel() in parallel. It blocks until all tasks have finished. func (m *Manager) Close() { var wg sync.WaitGroup - wg.Add(1) + wg.Add(2) go func() { m.Wait() wg.Done() }() - wg.Add(1) go func() { m.Cancel() wg.Done() diff --git a/background_test.go b/background_test.go index 71d6705..eaa7d0d 100644 --- a/background_test.go +++ b/background_test.go @@ -15,7 +15,7 @@ import ( func Test_NewManager(t *testing.T) { m := background.NewManager() assert.NotNil(t, m) - assert.IsType(t, &background.Manager{}, m) + assert.IsType(t, background.Manager{}, m) assert.EqualValues(t, 0, m.CountOf(background.TaskTypeOneOff)) assert.EqualValues(t, 0, m.CountOf(background.TaskTypeLoop)) } diff --git a/makefile b/makefile index 38b0c3a..6b4236c 100644 --- a/makefile +++ b/makefile @@ -8,5 +8,6 @@ test: force clean: rm -rf .cache + rm coverage.txt .PHONY: force