From 67c9cf4a2d05f603f8b9b03f221db5daf561fd23 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Sep 2025 11:21:12 +0000 Subject: [PATCH 1/3] chore(deps): bump actions/checkout from 4 to 5 in /.github/workflows Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 5. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: '5' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/pull-request.yaml | 4 ++-- .github/workflows/release.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pull-request.yaml b/.github/workflows/pull-request.yaml index 1cdc648..56d3d2a 100644 --- a/.github/workflows/pull-request.yaml +++ b/.github/workflows/pull-request.yaml @@ -17,7 +17,7 @@ jobs: scans: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 with: fetch-depth: 0 @@ -31,7 +31,7 @@ jobs: golang: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 with: fetch-depth: 0 diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index e71a1bb..02d0b1e 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Release uses: codfish/semantic-release-action@v3.5.0 env: From 71dbd4c8095951e182b111653d2ca9d3da2b1135 Mon Sep 17 00:00:00 2001 From: frag223 Date: Thu, 4 Sep 2025 17:45:40 +1000 Subject: [PATCH 2/3] fixing --- .gitignore | 2 ++ .golangci.yaml | 53 ++++++++++++++++++++++++++++++++++++++++++++++---- Makefile | 2 -- assert.go | 2 +- assert_test.go | 4 ++-- errors.go | 18 ++++++++++------- errors_test.go | 13 ++++++++----- odize.go | 20 +++++++++---------- types.go | 6 +++--- 9 files changed, 86 insertions(+), 34 deletions(-) diff --git a/.gitignore b/.gitignore index 3b735ec..82c4ca1 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,5 @@ # Go workspace file go.work + +.idea \ No newline at end of file diff --git a/.golangci.yaml b/.golangci.yaml index 634b8bf..70cd2b9 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,5 +1,50 @@ +version: "2" -linters-settings: - govet: - disable: - - printf \ No newline at end of file +linters: + enable: + - cyclop + - nestif + - bodyclose + - iface + - gosec + - errcheck + - err113 + - errchkjson + - errname + - errorlint + - exptostd + - fatcontext + - forbidigo + - forcetypeassert + - govet + - importas + - ireturn + - recvcheck + - sloglint + - staticcheck + - unparam + - unused + - wastedassign + + settings: + staticcheck: + checks: + - "-QF1012" + exclusions: + govet: + disable: + - printf + + generated: lax + + rules: + # Exclude some linters from running on tests files. + - path: _test\.go + linters: + - gocyclo + - cyclop + - dupl + - err113 + - gosec + - forbidigo + - exhaustruct \ No newline at end of file diff --git a/Makefile b/Makefile index 3fad1ce..5358253 100644 --- a/Makefile +++ b/Makefile @@ -31,9 +31,7 @@ test-watch: ## Run unit tests in watch mode scan: ## run security scan govulncheck ./... - gosec ./... golangci-lint run ./... - go vet ./... tools-get: ## Get project tools required go install golang.org/x/vuln/cmd/govulncheck@latest diff --git a/assert.go b/assert.go index be0ed88..f6c2aa7 100644 --- a/assert.go +++ b/assert.go @@ -8,7 +8,7 @@ import ( "testing" ) -// Assert value is nil +// AssertNil Assert value is nil // // Example: // diff --git a/assert_test.go b/assert_test.go index 146e38b..22c9a9b 100644 --- a/assert_test.go +++ b/assert_test.go @@ -1,7 +1,7 @@ package odize import ( - "fmt" + "errors" "strings" "testing" ) @@ -128,5 +128,5 @@ func TestAssertFalse(t *testing.T) { } func TestAssertError(t *testing.T) { - AssertError(t, fmt.Errorf("test")) + AssertError(t, errors.New("test")) } diff --git a/errors.go b/errors.go index 74d17f6..5281409 100644 --- a/errors.go +++ b/errors.go @@ -1,33 +1,37 @@ package odize -import "fmt" +import "errors" + +var ( + ErrTestAlreadyExists = errors.New("test already exists") +) // Error - return error string -func (e *ErrorList) Error() string { +func (e *ListError) Error() string { result := "" for _, item := range e.errors { - result += fmt.Sprintf("%s, ", item.Error()) + result += item.Error() + ", " } return result } // Unwrap - returns list of errors -func (e *ErrorList) Unwrap() []error { +func (e *ListError) Unwrap() []error { return e.errors } // Append - append error to list -func (e *ErrorList) Append(err error) { +func (e *ListError) Append(err error) { e.errors = append(e.errors, err) } -func (e *ErrorList) Len() int { +func (e *ListError) Len() int { return len(e.errors) } // Pop - remove the first error from the list and return -func (e *ErrorList) Pop() error { +func (e *ListError) Pop() error { if len(e.errors) == 0 { return nil } diff --git a/errors_test.go b/errors_test.go index 16d5943..5c514a0 100644 --- a/errors_test.go +++ b/errors_test.go @@ -6,7 +6,7 @@ import ( ) func TestError(t *testing.T) { - list := ErrorList{} + list := ListError{} list.Append(errors.New("expected")) if list.Error() != "expected, " { @@ -15,17 +15,20 @@ func TestError(t *testing.T) { } func TestPop(t *testing.T) { - list := ErrorList{} - list.Append(errors.New("first")) + firstErr := errors.New("first") + list := ListError{} + list.Append(firstErr) list.Append(errors.New("second")) expected := list.Pop() - if expected.Error() != "first" { + + if !errors.Is(expected, firstErr) { t.Errorf("expected %s, got %v ", "first", expected.Error()) } } + func TestPop_no_errors(t *testing.T) { - list := ErrorList{} + list := ListError{} expected := list.Pop() if expected != nil { diff --git a/odize.go b/odize.go index 604d6b0..e77fed5 100644 --- a/odize.go +++ b/odize.go @@ -2,6 +2,7 @@ package odize import ( + "errors" "fmt" "slices" "testing" @@ -12,12 +13,12 @@ import ( const ( // ODIZE_TAGS is the environment variable that is used to filter tests ODIZE_TAGS = "ODIZE_TAGS" - // ENV variable declared in pipelines such as Github Actions + // ENV_CI ENV variable declared in pipelines such as Github Actions ENV_CI = "CI" ) var ( - ErrTestOptionNotAllowedInCI = fmt.Errorf("test option 'Only' not allowed in CI environment") + ErrTestOptionNotAllowedInCI = errors.New("test option 'Only' not allowed in CI environment") ) // NewGroup - Create a new test group. @@ -98,11 +99,11 @@ func (tg *TestGroup) Run() error { tg.beforeAll() - entries, err := filterExecutableTests(tg.t, tg.isCIEnv, tg.registry) + entries, err := filterExecutableTests(tg.isCIEnv, tg.registry) if err != nil { // Stop Run, suite is in an invalid state tg.complete = true - return fmt.Errorf("Test group \"%s\" error: %w", tg.t.Name(), err) + return fmt.Errorf("test group \"%s\" error: %w", tg.t.Name(), err) } for _, entry := range entries { @@ -121,7 +122,7 @@ func (tg *TestGroup) Run() error { // registerTest registers a test to the group. Do not overwrite existing tests. func (tg *TestGroup) registerTest(name string, testFn TestFn, options TestOpts) error { if _, ok := tg.cache[name]; ok { - return fmt.Errorf("test already exists: %s", name) + return fmt.Errorf("%w: %s", ErrTestAlreadyExists, name) } tg.cache[name] = struct{}{} @@ -174,7 +175,6 @@ func shouldSkipTests(groupTags []string, envTags []string) bool { if len(groupTags) == 0 && len(envTags) == 0 { // run all tests - fmt.Println("running test") return false } @@ -189,8 +189,8 @@ func shouldSkipTests(groupTags []string, envTags []string) bool { // filterExecutableTests filters tests that are executable within the test group // Note that test option 'Only' is only used for debugging tests, and should not be used in a CI env. -func filterExecutableTests(t *testing.T, isCIEnv bool, tests []TestRegistryEntry) ([]TestRegistryEntry, error) { - filtered, err := filterOnlyAllowedTests(t, isCIEnv, tests) +func filterExecutableTests(isCIEnv bool, tests []TestRegistryEntry) ([]TestRegistryEntry, error) { + filtered, err := filterOnlyAllowedTests(isCIEnv, tests) if err != nil { return filtered, err } @@ -220,8 +220,8 @@ func filterExecutableTests(t *testing.T, isCIEnv bool, tests []TestRegistryEntry // filterOnlyAllowedTests filters tests that are marked as only within a test group // If the framework detects that the test is running under a CI environment and the group has tests with 'Only', then it will return an error -func filterOnlyAllowedTests(t *testing.T, isCIEnv bool, tests []TestRegistryEntry) ([]TestRegistryEntry, error) { - filtered := []TestRegistryEntry{} +func filterOnlyAllowedTests(isCIEnv bool, tests []TestRegistryEntry) ([]TestRegistryEntry, error) { + var filtered []TestRegistryEntry for _, test := range tests { if test.options.Only && isCIEnv { diff --git a/types.go b/types.go index 7b377ba..fcaa9c0 100644 --- a/types.go +++ b/types.go @@ -17,7 +17,7 @@ type TestGroup struct { complete bool registry []TestRegistryEntry cache map[string]struct{} - errors ErrorList + errors ListError isCIEnv bool } @@ -41,7 +41,7 @@ type TestOpts struct { Skip bool } -// ErrorList - keep track of a number of errors -type ErrorList struct { +// ListError - keep track of a number of errors +type ListError struct { errors []error } From 60feb09d5822d95da4da0c8f1dff420f081d40fa Mon Sep 17 00:00:00 2001 From: frag223 Date: Thu, 4 Sep 2025 20:54:09 +1000 Subject: [PATCH 3/3] clean up --- .github/workflows/pull-request.yaml | 8 ++------ Makefile | 5 ++--- assert.go | 2 +- go.mod | 2 +- odize_log.go | 7 ------- 5 files changed, 6 insertions(+), 18 deletions(-) diff --git a/.github/workflows/pull-request.yaml b/.github/workflows/pull-request.yaml index 56d3d2a..bad9e69 100644 --- a/.github/workflows/pull-request.yaml +++ b/.github/workflows/pull-request.yaml @@ -8,10 +8,6 @@ on: pull_request: types: [opened, synchronize, reopened] - -env: - GOLANG_VERSION: 1.21 - jobs: scans: @@ -35,10 +31,10 @@ jobs: with: fetch-depth: 0 - - name: Setup golang ${{ env.GOLANG_VERSION }} + - name: Setup golang uses: actions/setup-go@v5 with: - go-version: ${{ env.GOLANG_VERSION }} + go-version-file: go.mod - name: install tools run: make tools-get diff --git a/Makefile b/Makefile index 5358253..5ea038d 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ BINARY_PATH ?= "dist" ci: log scan test ## Run CI checks test: ## Run unit tests - go test -v --short -cover -failfast ./... + go test --short -cover -failfast ./... test-watch: ## Run unit tests in watch mode gow test -v --short -cover -failfast ./... @@ -35,8 +35,7 @@ scan: ## run security scan tools-get: ## Get project tools required go install golang.org/x/vuln/cmd/govulncheck@latest - go install github.com/securego/gosec/v2/cmd/gosec@latest - go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest + go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.2.2 # HELP # This will output the help for each task diff --git a/assert.go b/assert.go index f6c2aa7..2227e72 100644 --- a/assert.go +++ b/assert.go @@ -82,7 +82,7 @@ func AssertEqual(t *testing.T, expected any, actual any) { t.Helper() if !isEqual(expected, actual) { - logf(t, decorateDiff(expected, actual)) + log(t, decorateDiff(expected, actual)) } } diff --git a/go.mod b/go.mod index 75778ca..9b7ebd8 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/code-gorilla-au/odize -go 1.21.5 +go 1.25.0 require github.com/code-gorilla-au/env v1.1.1 diff --git a/odize_log.go b/odize_log.go index 4525c95..f6a8bed 100644 --- a/odize_log.go +++ b/odize_log.go @@ -1,7 +1,6 @@ package odize import ( - "fmt" "testing" ) @@ -12,9 +11,3 @@ func log(t *testing.T, args ...any) { t.Error(args...) t.FailNow() } - -// logf log with formatting -func logf(t *testing.T, format string, args ...any) { - t.Helper() - log(t, fmt.Sprintf(format, args...)) -}