From 31ac13e8393f9d6d089dd3536b067e92b34c4082 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Tue, 20 Jan 2026 11:31:05 +0100 Subject: [PATCH 1/3] test: replace context.Background() with t.Context() Replace context.Background() with t.Context() in test files for modern Go testing patterns (Go 1.24+). Assisted-By: cagent --- engine/internal/runtime/plugin_test.go | 8 ++++---- store/keychain/keychain_test.go | 11 +++++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/engine/internal/runtime/plugin_test.go b/engine/internal/runtime/plugin_test.go index b07f0d88..db6ec35d 100644 --- a/engine/internal/runtime/plugin_test.go +++ b/engine/internal/runtime/plugin_test.go @@ -76,7 +76,7 @@ func Test_newPlugin(t *testing.T) { assert.Equal(t, pluginNameFromTestName(t), p.Name().String()) assert.Equal(t, version.String(), p.Version().String()) assert.Equal(t, pattern, p.Pattern().String()) - s, err := p.GetSecrets(context.Background(), testdummy.MockSecretPattern) + s, err := p.GetSecrets(t.Context(), testdummy.MockSecretPattern) require.NoError(t, err) require.NotEmpty(t, s) assert.Equal(t, testdummy.MockSecretValue, string(s[0].Value)) @@ -108,7 +108,7 @@ func Test_newPlugin(t *testing.T) { cmd, ) require.NoError(t, err) - _, err = p.GetSecrets(context.Background(), testdummy.MockSecretPattern) + _, err = p.GetSecrets(t.Context(), testdummy.MockSecretPattern) assert.ErrorContains(t, err, errGetSecret) assert.NoError(t, p.Close()) r, err := parseOutput() @@ -181,12 +181,12 @@ func Test_newPlugin(t *testing.T) { cmd, ) require.NoError(t, err) - _, err = p.GetSecrets(context.Background(), testdummy.MockSecretPattern) + _, err = p.GetSecrets(t.Context(), testdummy.MockSecretPattern) require.NoError(t, err) require.NoError(t, p.Watcher().Kill()) assert.NoError(t, testhelper.WaitForClosedWithTimeout(p.Closed())) assert.ErrorContains(t, p.Close(), "stopped unexpectedly") - _, err = p.GetSecrets(context.Background(), testdummy.MockSecretPattern) + _, err = p.GetSecrets(t.Context(), testdummy.MockSecretPattern) assert.ErrorIs(t, err, yamux.ErrSessionShutdown) _, err = parseOutput() assert.ErrorContains(t, err, "failed to unmarshal ''") diff --git a/store/keychain/keychain_test.go b/store/keychain/keychain_test.go index de8efd7f..dd311811 100644 --- a/store/keychain/keychain_test.go +++ b/store/keychain/keychain_test.go @@ -1,7 +1,6 @@ package keychain import ( - "context" "errors" "testing" @@ -72,7 +71,7 @@ func TestKeychain(t *testing.T) { Password: "bob-password", } t.Cleanup(func() { - require.NoError(t, ks.Delete(context.Background(), id)) + require.NoError(t, ks.Delete(t.Context(), id)) }) require.NoError(t, ks.Save(t.Context(), id, creds)) }) @@ -85,7 +84,7 @@ func TestKeychain(t *testing.T) { Password: "bob-password", } t.Cleanup(func() { - require.NoError(t, ks.Delete(context.Background(), id)) + require.NoError(t, ks.Delete(t.Context(), id)) }) require.NoError(t, ks.Save(t.Context(), id, creds)) secret, err := ks.Get(t.Context(), id) @@ -125,7 +124,7 @@ func TestKeychain(t *testing.T) { } t.Cleanup(func() { for id := range moreCreds { - require.NoError(t, ks.Delete(context.Background(), id)) + require.NoError(t, ks.Delete(t.Context(), id)) } }) @@ -272,7 +271,7 @@ func TestKeychain(t *testing.T) { id, err := store.ParseID("something/will/fail") require.NoError(t, err) t.Cleanup(func() { - require.NoError(t, kc.Delete(context.Background(), id)) + require.NoError(t, kc.Delete(t.Context(), id)) }) require.NoError(t, kc.Save(t.Context(), id, &mustUnmarshalError{})) _, err = kc.Get(t.Context(), id) @@ -286,7 +285,7 @@ func TestKeychain(t *testing.T) { id, err := store.ParseID("something/will/fail") require.NoError(t, err) t.Cleanup(func() { - require.NoError(t, kc.Delete(context.Background(), id)) + require.NoError(t, kc.Delete(t.Context(), id)) }) require.NoError(t, kc.Save(t.Context(), id, &mustUnmarshalError{})) _, err = kc.GetAllMetadata(t.Context()) From 479fdcd8a52cd64504b28564f4409e4f948aa942 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Tue, 20 Jan 2026 11:33:50 +0100 Subject: [PATCH 2/3] chore: add forbidigo lint rules for modern Go test patterns Add golangci-lint rules to enforce: - Using t.TempDir() instead of os.MkdirTemp in tests - Using t.Context() instead of context.Background()/TODO() in tests - No print statements in test code Assisted-By: cagent --- .golangci.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.golangci.yml b/.golangci.yml index 2f49e41d..d648a839 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -3,6 +3,7 @@ linters: default: none enable: - errcheck + - forbidigo - gocyclo - govet - ineffassign @@ -16,6 +17,12 @@ linters: - unparam - unused settings: + forbidigo: + forbid: + - pattern: '^os\.MkdirTemp$' + msg: "use t.TempDir() instead" + - pattern: '^context\.(Background|TODO)$' + msg: "use t.Context() instead" gocritic: disabled-checks: - dupArg @@ -44,6 +51,12 @@ linters: - builtin$ - examples$ - vendor$ + rules: + # Scope test-specific forbidigo rules to test files only + - path-except: '_test\.go$' + linters: + - forbidigo + text: 'use t\.' formatters: enable: - gofumpt From 002e05b61e89730a8dd6de4339f3e9b38976b2e2 Mon Sep 17 00:00:00 2001 From: Alano Terblanche <18033717+Benehiko@users.noreply.github.com> Date: Wed, 21 Jan 2026 15:29:08 +0100 Subject: [PATCH 3/3] Update .golangci.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index d648a839..90687107 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -53,7 +53,7 @@ linters: - vendor$ rules: # Scope test-specific forbidigo rules to test files only - - path-except: '_test\.go$' + - path: '_test\.go$' linters: - forbidigo text: 'use t\.'