From 5b2bebf1917f7d440d328127bbec50979427419d Mon Sep 17 00:00:00 2001 From: Andrey Petrov Date: Sun, 2 Nov 2025 13:26:53 +0300 Subject: [PATCH] examples: fix staticcheck issues (SA4022, SA1029) in kind_with_config Fix two staticcheck issues found in examples/kind/kind_with_config: - Avoid comparing address of variable to nil (SA4022) - Use dedicated key type instead of string for context.WithValue (SA1029) Although examples are excluded from linter checks, they are widely copied by users. Fixing these issues prevents spreading bad patterns and keeps the examples correct. Verified with: staticcheck ./examples/kind/kind_with_config/... go test ./examples/kind/kind_with_config/... Signed-off-by: Andrey Petrov --- .../kind/kind_with_config/kind_with_config_test.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/examples/kind/kind_with_config/kind_with_config_test.go b/examples/kind/kind_with_config/kind_with_config_test.go index 49d6a16a..44a7ee14 100644 --- a/examples/kind/kind_with_config/kind_with_config_test.go +++ b/examples/kind/kind_with_config/kind_with_config_test.go @@ -28,6 +28,11 @@ import ( "sigs.k8s.io/e2e-framework/pkg/features" ) +// unexported key type to avoid collisions in context (SA1029) +type depKeyType struct{} + +var depKey depKeyType + func TestKindCluster(t *testing.T) { deploymentFeature := features.New("appsv1/deployment"). Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { @@ -44,13 +49,11 @@ func TestKindCluster(t *testing.T) { if err := cfg.Client().Resources().Get(ctx, "test-deployment", cfg.Namespace(), &dep); err != nil { t.Fatal(err) } - if &dep != nil { - t.Logf("deployment found: %s", dep.Name) - } - return context.WithValue(ctx, "test-deployment", &dep) + t.Logf("deployment found: %s", dep.Name) + return context.WithValue(ctx, depKey, &dep) }). Teardown(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - dep := ctx.Value("test-deployment").(*appsv1.Deployment) + dep := ctx.Value(depKey).(*appsv1.Deployment) if err := cfg.Client().Resources().Delete(ctx, dep); err != nil { t.Fatal(err) }