(t *testing.T)
| 210 | } |
| 211 | |
| 212 | func TestPolicyCacheFromContext(t *testing.T) { |
| 213 | tests := []struct { |
| 214 | name string |
| 215 | setupContext func() context.Context |
| 216 | expectedFound bool |
| 217 | expectedCache *PolicyCache |
| 218 | }{ |
| 219 | { |
| 220 | name: "PolicyCache not in context", |
| 221 | setupContext: func() context.Context { |
| 222 | return context.Background() |
| 223 | }, |
| 224 | expectedFound: false, |
| 225 | expectedCache: nil, |
| 226 | }, |
| 227 | { |
| 228 | name: "PolicyCache in context", |
| 229 | setupContext: func() context.Context { |
| 230 | ctx := context.Background() |
| 231 | cache := NewPolicyCache(ctx) |
| 232 | return WithPolicyCache(ctx, cache) |
| 233 | }, |
| 234 | expectedFound: true, |
| 235 | expectedCache: func() *PolicyCache { |
| 236 | cache := NewPolicyCache(context.Background()) |
| 237 | return cache |
| 238 | }(), |
| 239 | }, |
| 240 | { |
| 241 | name: "nil PolicyCache in context", |
| 242 | setupContext: func() context.Context { |
| 243 | ctx := context.Background() |
| 244 | return context.WithValue(ctx, policyCacheKey, (*PolicyCache)(nil)) |
| 245 | }, |
| 246 | expectedFound: true, |
| 247 | expectedCache: nil, |
| 248 | }, |
| 249 | } |
| 250 | |
| 251 | for _, tt := range tests { |
| 252 | t.Run(tt.name, func(t *testing.T) { |
| 253 | ctx := tt.setupContext() |
| 254 | |
| 255 | // Execute test |
| 256 | retrievedCache, found := PolicyCacheFromContext(ctx) |
| 257 | |
| 258 | // Assert results |
| 259 | assert.Equal(t, tt.expectedFound, found) |
| 260 | if tt.expectedCache == nil { |
| 261 | assert.Nil(t, retrievedCache) |
| 262 | } else { |
| 263 | assert.NotNil(t, retrievedCache) |
| 264 | } |
| 265 | }) |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | func TestWithPolicyCache(t *testing.T) { |
nothing calls this directly
no test coverage detected