From 26f48ebc7ccee766a1e28b5d3bbb5ac2204099b1 Mon Sep 17 00:00:00 2001 From: Rebecca Mahany-Horton Date: Thu, 14 Dec 2023 09:50:42 -0500 Subject: [PATCH] Enable context-keys-type rule --- .golangci.yml | 2 ++ pkg/make/builder_test.go | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index f86533e32..e3154bd55 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -55,6 +55,8 @@ linters-settings: disabled: false - name: context-as-argument disabled: false + - name: context-keys-type + disabled: false - name: error-return disabled: false - name: errorf diff --git a/pkg/make/builder_test.go b/pkg/make/builder_test.go index e21b6bc13..32191883a 100644 --- a/pkg/make/builder_test.go +++ b/pkg/make/builder_test.go @@ -17,6 +17,14 @@ import ( "github.com/stretchr/testify/require" ) +type contextKey string + +func (c contextKey) String() string { + return string(c) +} + +const contextKeyEnv contextKey = "ENV" + func helperCommandContext(ctx context.Context, command string, args ...string) (cmd *exec.Cmd) { cs := []string{"-test.run=TestHelperProcess", "--", command} cs = append(cs, args...) @@ -24,7 +32,7 @@ func helperCommandContext(ctx context.Context, command string, args ...string) ( cmd.Env = []string{"GO_WANT_HELPER_PROCESS=1"} // Do we have an ENV key? (type assert) - if ctxEnv, ok := ctx.Value("ENV").([]string); ok { + if ctxEnv, ok := ctx.Value(contextKeyEnv).([]string); ok { cmd.Env = append(cmd.Env, ctxEnv...) } @@ -191,7 +199,8 @@ func TestGetVersion(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - ctx = context.WithValue(ctx, "ENV", []string{fmt.Sprintf("FAKE_GIT_DESCRIBE=%s", tt.in)}) + + ctx = context.WithValue(ctx, contextKeyEnv, []string{fmt.Sprintf("FAKE_GIT_DESCRIBE=%s", tt.in)}) os.Setenv("FAKE_GIT_DESCRIBE", tt.in) ver, err := b.getVersion(ctx) if tt.err == true {