Skip to content

Commit

Permalink
Enable context-keys-type rule
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaMahany committed Dec 14, 2023
1 parent b16ec4b commit 26f48eb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions pkg/make/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,22 @@ 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...)
cmd = exec.CommandContext(ctx, os.Args[0], cs...) //nolint:forbidigo // Fine to use exec.CommandContext in tests
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...)
}

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 26f48eb

Please sign in to comment.