From f5a03af9ce340ba3152354682f54d8eceabc3270 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sat, 22 Mar 2025 01:23:12 +0000 Subject: [PATCH] ci(deps): update actions and lint config to get them all running again (#5) --- .github/workflows/ci.yml | 53 ++++++-------- .golangci.yml | 12 +--- example_test.go | 22 +++--- golden.go | 145 +++++++++++++++++++-------------------- 4 files changed, 102 insertions(+), 130 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ad6a567..ba17331 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,29 +6,28 @@ jobs: lint: name: Lint runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: read + checks: write steps: - - uses: actions/checkout@v2 - - name: golangci-lint - uses: golangci/golangci-lint-action@v2 + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 with: - version: v1.42 - env: - VERBOSE: "true" + go-version-file: go.mod + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: v1.64 tidy: name: Tidy runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 with: - go-version: 1.15 - - uses: actions/cache@v2 - with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- + go-version-file: go.mod - name: Check if mods are tidy run: make check-tidy @@ -36,18 +35,12 @@ jobs: name: Coverage runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 with: - go-version: 1.15 - - uses: actions/cache@v2 - with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- + go-version-file: go.mod - name: Publish coverage - uses: paambaati/codeclimate-action@v2.7.4 + uses: paambaati/codeclimate-action@v9.0.0 env: VERBOSE: "true" GOMAXPROCS: 4 @@ -73,15 +66,9 @@ jobs: - "1.17" runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 with: go-version: ${{ matrix.go_version }} - - uses: actions/cache@v2 - with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - name: Run tests run: go test -v -count=1 -race ./... diff --git a/.golangci.yml b/.golangci.yml index bee01fe..af35e6e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -4,18 +4,13 @@ linters-settings: statements: 150 gocyclo: min-complexity: 20 - golint: - min-confidence: 0 govet: - check-shadowing: true enable-all: true disable: - fieldalignment lll: line-length: 80 tab-width: 4 - maligned: - suggest-new: true misspell: locale: US @@ -24,13 +19,11 @@ linters: enable: - asciicheck - bodyclose - - deadcode - - depguard + - copyloopvar - durationcheck - errcheck - errorlint - exhaustive - - exportloopref - funlen - gochecknoinits - goconst @@ -58,13 +51,10 @@ linters: - rowserrcheck - sqlclosecheck - staticcheck - - structcheck - - tparallel - typecheck - unconvert - unparam - unused - - varcheck - wastedassign - whitespace diff --git a/example_test.go b/example_test.go index d60f678..39c5384 100644 --- a/example_test.go +++ b/example_test.go @@ -16,8 +16,7 @@ type MyStruct struct { // TestExampleMyStruct reads/writes the following golden file: // -// testdata/TestExampleMyStruct.golden -// +// testdata/TestExampleMyStruct.golden func TestExampleMyStruct(t *testing.T) { got, err := json.Marshal(&MyStruct{Foo: "Bar"}) require.NoError(t, err) @@ -32,9 +31,8 @@ func TestExampleMyStruct(t *testing.T) { // TestExampleMyStructTabular reads/writes the following golden files: // -// testdata/TestExampleMyStructTabular/empty_struct.golden -// testdata/TestExampleMyStructTabular/full_struct.golden -// +// testdata/TestExampleMyStructTabular/empty_struct.golden +// testdata/TestExampleMyStructTabular/full_struct.golden func TestExampleMyStructTabular(t *testing.T) { tests := []struct { name string @@ -60,9 +58,8 @@ func TestExampleMyStructTabular(t *testing.T) { // TestExampleMyStructP reads/writes the following golden file: // -// testdata/TestExampleMyStructP/json.golden -// testdata/TestExampleMyStructP/xml.golden -// +// testdata/TestExampleMyStructP/json.golden +// testdata/TestExampleMyStructP/xml.golden func TestExampleMyStructP(t *testing.T) { gotJSON, _ := json.Marshal(&MyStruct{Foo: "Bar"}) gotXML, _ := xml.Marshal(&MyStruct{Foo: "Bar"}) @@ -78,11 +75,10 @@ func TestExampleMyStructP(t *testing.T) { // TestExampleMyStructTabularP reads/writes the following golden file: // -// testdata/TestExampleMyStructTabularP/empty_struct/json.golden -// testdata/TestExampleMyStructTabularP/empty_struct/xml.golden -// testdata/TestExampleMyStructTabularP/full_struct/json.golden -// testdata/TestExampleMyStructTabularP/full_struct/xml.golden -// +// testdata/TestExampleMyStructTabularP/empty_struct/json.golden +// testdata/TestExampleMyStructTabularP/empty_struct/xml.golden +// testdata/TestExampleMyStructTabularP/full_struct/json.golden +// testdata/TestExampleMyStructTabularP/full_struct/xml.golden func TestExampleMyStructTabularP(t *testing.T) { tests := []struct { name string diff --git a/golden.go b/golden.go index 948d369..a62ae29 100644 --- a/golden.go +++ b/golden.go @@ -6,120 +6,119 @@ // compatible with Linux, macOS and Windows systems regardless of what crazy // characters might be in a subtest's name. // -// Usage +// # Usage // // Typical usage should look something like this: // -// func TestExampleMyStruct(t *testing.T) { -// got, err := json.Marshal(&MyStruct{Foo: "Bar"}) -// require.NoError(t, err) +// func TestExampleMyStruct(t *testing.T) { +// got, err := json.Marshal(&MyStruct{Foo: "Bar"}) +// require.NoError(t, err) // -// if golden.Update() { -// golden.Set(t, got) -// } -// want := golden.Get(t) +// if golden.Update() { +// golden.Set(t, got) +// } +// want := golden.Get(t) // -// assert.Equal(t, want, got) -// } +// assert.Equal(t, want, got) +// } // // The above example will read/write to: // -// testdata/TestExampleMyStruct.golden +// testdata/TestExampleMyStruct.golden // // To update the golden file (have golden.Update() return true), simply set the // GOLDEN_UPDATE environment variable to one of "1", "y", "t", "yes", "on", or // "true" when running tests. // -// Sub-Tests +// # Sub-Tests // // As the golden filename is based on t.Name(), it works with sub-tests too, // ensuring each sub-test gets it's own golden file. For example: // -// func TestExampleMyStructTabular(t *testing.T) { -// tests := []struct { -// name string -// obj *MyStruct -// }{ -// {name: "empty struct", obj: &MyStruct{}}, -// {name: "full struct", obj: &MyStruct{Foo: "Bar"}}, -// } -// for _, tt := range tests { -// t.Run(tt.name, func(t *testing.T) { -// got, err := json.Marshal(tt.obj) -// require.NoError(t, err) +// func TestExampleMyStructTabular(t *testing.T) { +// tests := []struct { +// name string +// obj *MyStruct +// }{ +// {name: "empty struct", obj: &MyStruct{}}, +// {name: "full struct", obj: &MyStruct{Foo: "Bar"}}, +// } +// for _, tt := range tests { +// t.Run(tt.name, func(t *testing.T) { +// got, err := json.Marshal(tt.obj) +// require.NoError(t, err) // -// if golden.Update() { -// golden.Set(t, got) -// } -// want := golden.Get(t) +// if golden.Update() { +// golden.Set(t, got) +// } +// want := golden.Get(t) // -// assert.Equal(t, want, got) -// }) -// } -// } +// assert.Equal(t, want, got) +// }) +// } +// } // // The above example will read/write to: // -// testdata/TestExampleMyStructTabular/empty_struct.golden -// testdata/TestExampleMyStructTabular/full_struct.golden +// testdata/TestExampleMyStructTabular/empty_struct.golden +// testdata/TestExampleMyStructTabular/full_struct.golden // -// Multiple Golden Files in a Single Test +// # Multiple Golden Files in a Single Test // // The "P" suffixed methods, GetP(), SetP(), and FileP(), all take a name // argument which allows using specific golden files within a given *testing.T // instance. // -// func TestExampleMyStructP(t *testing.T) { -// gotJSON, _ := json.Marshal(&MyStruct{Foo: "Bar"}) -// gotXML, _ := xml.Marshal(&MyStruct{Foo: "Bar"}) +// func TestExampleMyStructP(t *testing.T) { +// gotJSON, _ := json.Marshal(&MyStruct{Foo: "Bar"}) +// gotXML, _ := xml.Marshal(&MyStruct{Foo: "Bar"}) // -// if golden.Update() { -// golden.SetP(t, "json", gotJSON) -// golden.SetP(t, "xml", gotXML) -// } +// if golden.Update() { +// golden.SetP(t, "json", gotJSON) +// golden.SetP(t, "xml", gotXML) +// } // -// assert.Equal(t, golden.GetP(t, "json"), gotJSON) -// assert.Equal(t, golden.GetP(t, "xml"), gotXML) -// } +// assert.Equal(t, golden.GetP(t, "json"), gotJSON) +// assert.Equal(t, golden.GetP(t, "xml"), gotXML) +// } // // The above example will read/write to: // -// testdata/TestExampleMyStructP/json.golden -// testdata/TestExampleMyStructP/xml.golden +// testdata/TestExampleMyStructP/json.golden +// testdata/TestExampleMyStructP/xml.golden // // This works with tabular tests too of course: // -// func TestExampleMyStructTabularP(t *testing.T) { -// tests := []struct { -// name string -// obj *MyStruct -// }{ -// {name: "empty struct", obj: &MyStruct{}}, -// {name: "full struct", obj: &MyStruct{Foo: "Bar"}}, -// } -// for _, tt := range tests { -// t.Run(tt.name, func(t *testing.T) { -// gotJSON, _ := json.Marshal(tt.obj) -// gotXML, _ := xml.Marshal(tt.obj) +// func TestExampleMyStructTabularP(t *testing.T) { +// tests := []struct { +// name string +// obj *MyStruct +// }{ +// {name: "empty struct", obj: &MyStruct{}}, +// {name: "full struct", obj: &MyStruct{Foo: "Bar"}}, +// } +// for _, tt := range tests { +// t.Run(tt.name, func(t *testing.T) { +// gotJSON, _ := json.Marshal(tt.obj) +// gotXML, _ := xml.Marshal(tt.obj) // -// if golden.Update() { -// golden.SetP(t, "json", gotJSON) -// golden.SetP(t, "xml", gotXML) -// } +// if golden.Update() { +// golden.SetP(t, "json", gotJSON) +// golden.SetP(t, "xml", gotXML) +// } // -// assert.Equal(t, golden.GetP(t, "json"), gotJSON) -// assert.Equal(t, golden.GetP(t, "xml"), gotXML) -// }) -// } -// } +// assert.Equal(t, golden.GetP(t, "json"), gotJSON) +// assert.Equal(t, golden.GetP(t, "xml"), gotXML) +// }) +// } +// } // // The above example will read/write to: // -// testdata/TestExampleMyStructTabularP/empty_struct/json.golden -// testdata/TestExampleMyStructTabularP/empty_struct/xml.golden -// testdata/TestExampleMyStructTabularP/full_struct/json.golden -// testdata/TestExampleMyStructTabularP/full_struct/xml.golden -// +// testdata/TestExampleMyStructTabularP/empty_struct/json.golden +// testdata/TestExampleMyStructTabularP/empty_struct/xml.golden +// testdata/TestExampleMyStructTabularP/full_struct/json.golden +// testdata/TestExampleMyStructTabularP/full_struct/xml.golden package golden import (