Skip to content

Commit 0b9dd7a

Browse files
committed
Fix linter errors from CI
1 parent 55c16ee commit 0b9dd7a

File tree

5 files changed

+21
-33
lines changed

5 files changed

+21
-33
lines changed

pkg/remoteresolution/cache/cache_test.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ func TestResolverCache(t *testing.T) {
409409

410410
// Wait for expiration with polling to make test more reliable
411411
expired := false
412-
for i := 0; i < 20; i++ { // Max 200ms wait
412+
for range 20 { // Max 200ms wait
413413
time.Sleep(10 * time.Millisecond)
414414
if _, ok := cache.Get("http", expiringParams); !ok {
415415
expired = true
@@ -533,10 +533,8 @@ func TestResolverCacheOperations(t *testing.T) {
533533

534534
if v, found := cache.Get(resolverType, params); !found {
535535
t.Error("Expected to find value in cache")
536-
} else {
537-
if string(v.Data()) != "test-value" {
538-
t.Errorf("Expected data 'test-value', got %s", string(v.Data()))
539-
}
536+
} else if string(v.Data()) != "test-value" {
537+
t.Errorf("Expected data 'test-value', got %s", string(v.Data()))
540538
}
541539

542540
// Verify Add returns annotated resource
@@ -561,17 +559,15 @@ func TestResolverCacheOperations(t *testing.T) {
561559

562560
if v, found := cache.Get("bundle", expirationParams); !found {
563561
t.Error("Expected to find value in cache")
564-
} else {
565-
if string(v.Data()) != "expiring-value" {
566-
t.Errorf("Expected data 'expiring-value', got %s", string(v.Data()))
567-
}
562+
} else if string(v.Data()) != "expiring-value" {
563+
t.Errorf("Expected data 'expiring-value', got %s", string(v.Data()))
568564
}
569565

570566
// Wait for expiration with polling for more reliable test
571567
expired := false
572568
maxWait := customTTL + 100*time.Millisecond
573569
iterations := int(maxWait / (10 * time.Millisecond))
574-
for i := 0; i < iterations; i++ {
570+
for range iterations {
575571
time.Sleep(10 * time.Millisecond)
576572
if _, found := cache.Get("bundle", expirationParams); !found {
577573
expired = true

pkg/remoteresolution/cache/injection/cache_test.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestKey(t *testing.T) {
3131
key2 := Key{}
3232

3333
// Keys should be equivalent when used as context keys
34-
ctx := context.Background()
34+
ctx := t.Context()
3535
ctx = context.WithValue(ctx, key1, "test-value")
3636

3737
value := ctx.Value(key2)
@@ -55,27 +55,27 @@ func TestSharedCacheInitialization(t *testing.T) {
5555
func TestWithCacheFromConfig(t *testing.T) {
5656
tests := []struct {
5757
name string
58-
ctx context.Context
58+
setupCtx func() context.Context
5959
cfg *rest.Config
6060
expectCache bool
6161
}{
6262
{
6363
name: "basic context with config",
64-
ctx: context.Background(),
64+
setupCtx: func() context.Context { return t.Context() },
6565
cfg: &rest.Config{},
6666
expectCache: true,
6767
},
6868
{
6969
name: "context with logger",
70-
ctx: logtesting.TestContextWithLogger(t),
70+
setupCtx: func() context.Context { return logtesting.TestContextWithLogger(t) },
7171
cfg: &rest.Config{},
7272
expectCache: true,
7373
},
7474
}
7575

7676
for _, tt := range tests {
7777
t.Run(tt.name, func(t *testing.T) {
78-
result := withCacheFromConfig(tt.ctx, tt.cfg)
78+
result := withCacheFromConfig(tt.setupCtx(), tt.cfg)
7979

8080
// Check that result context contains cache
8181
cache := result.Value(Key{})
@@ -86,10 +86,7 @@ func TestWithCacheFromConfig(t *testing.T) {
8686
// Check that cache is functional (don't need type assertion for this test)
8787
if tt.expectCache && cache != nil {
8888
// The fact that it was stored and retrieved indicates correct type
89-
// Just check that we have a non-nil interface value
90-
if cache == nil {
91-
t.Errorf("Expected non-nil cache")
92-
}
89+
// Cache is non-nil as verified by outer condition, so it's functional
9390
}
9491
})
9592
}
@@ -105,15 +102,15 @@ func TestGet(t *testing.T) {
105102
{
106103
name: "context without cache",
107104
setupContext: func() context.Context {
108-
return context.Background()
105+
return t.Context()
109106
},
110107
expectNotNil: true,
111108
expectSameInstance: false, // Should get fallback instance
112109
},
113110
{
114111
name: "context with cache",
115112
setupContext: func() context.Context {
116-
ctx := context.Background()
113+
ctx := t.Context()
117114
testCache := cache.NewResolverCache(100)
118115
return context.WithValue(ctx, Key{}, testCache)
119116
},
@@ -150,7 +147,7 @@ func TestGet(t *testing.T) {
150147

151148
func TestGetConsistency(t *testing.T) {
152149
// Test that Get returns consistent results for fallback case
153-
ctx := context.Background()
150+
ctx := t.Context()
154151

155152
cache1 := Get(ctx)
156153
cache2 := Get(ctx)
@@ -166,7 +163,7 @@ func TestGetConsistency(t *testing.T) {
166163

167164
func TestGetWithInjectedCache(t *testing.T) {
168165
// Test that Get returns the injected cache when available
169-
ctx := context.Background()
166+
ctx := t.Context()
170167
testCache := cache.NewResolverCache(50)
171168
ctx = context.WithValue(ctx, Key{}, testCache)
172169

pkg/remoteresolution/resolver/cluster/resolver_integration_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ import (
5151
"knative.dev/pkg/system"
5252
_ "knative.dev/pkg/system/testing"
5353
"sigs.k8s.io/yaml"
54-
55-
5654
)
5755

5856
const (
@@ -527,9 +525,6 @@ func resolverDisabledContext() context.Context {
527525
return frameworktesting.ContextWithClusterResolverDisabled(context.Background())
528526
}
529527

530-
/*
531-
*/
532-
533528
func TestResolveWithDisabledResolver(t *testing.T) {
534529
ctx := frameworktesting.ContextWithClusterResolverDisabled(t.Context())
535530
resolver := &cluster.Resolver{}

pkg/remoteresolution/resolver/framework/cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type ImmutabilityChecker interface {
4242

4343
// ShouldUseCache determines whether caching should be used based on:
4444
// 1. Task/Pipeline cache parameter (highest priority)
45-
// 2. ConfigMap default-cache-mode (middle priority)
45+
// 2. ConfigMap default-cache-mode (middle priority)
4646
// 3. System default for resolver type (lowest priority)
4747
func ShouldUseCache(ctx context.Context, resolver ImmutabilityChecker, params []pipelinev1.Param, resolverType string) bool {
4848
// Get cache mode from task parameter

pkg/remoteresolution/resolver/framework/cache_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func TestShouldUseCache(t *testing.T) {
222222
resolver := &mockImmutabilityChecker{immutable: tt.immutable}
223223

224224
// Create context with config
225-
ctx := context.Background()
225+
ctx := t.Context()
226226
ctx = resolutionframework.InjectResolverConfigToContext(ctx, tt.configMap)
227227

228228
// Test ShouldUseCache
@@ -327,7 +327,7 @@ func TestShouldUseCachePrecedence(t *testing.T) {
327327
}
328328

329329
// Setup context with resolver config
330-
ctx := context.Background()
330+
ctx := t.Context()
331331
if len(tt.configMap) > 0 {
332332
ctx = resolutionframework.InjectResolverConfigToContext(ctx, tt.configMap)
333333
}
@@ -554,7 +554,7 @@ func TestShouldUseCacheBundleResolver(t *testing.T) {
554554
},
555555
}...)
556556

557-
ctx := context.Background()
557+
ctx := t.Context()
558558

559559
// Test the cache decision logic
560560
actual := framework.ShouldUseCache(ctx, resolver, params, "bundle")
@@ -614,7 +614,7 @@ func TestRunCacheOperations(t *testing.T) {
614614
}
615615

616616
// Create context with cache injection
617-
ctx := context.Background()
617+
ctx := t.Context()
618618
ctx = context.WithValue(ctx, cacheinjection.Key{}, testCache)
619619

620620
// Track if resolve function was called

0 commit comments

Comments
 (0)