TestSetContainerPinEdgeCases verifies SetContainerPin behaviour with edge case inputs.
(t *testing.T)
| 291 | |
| 292 | // TestSetContainerPinEdgeCases verifies SetContainerPin behaviour with edge case inputs. |
| 293 | func TestSetContainerPinEdgeCases(t *testing.T) { |
| 294 | tests := []struct { |
| 295 | name string |
| 296 | image string |
| 297 | digest string |
| 298 | pinnedImage string |
| 299 | wantOK bool // whether GetContainerPin should find it |
| 300 | }{ |
| 301 | { |
| 302 | name: "valid pin", |
| 303 | image: "node:lts-alpine", |
| 304 | digest: "sha256:abc123", |
| 305 | pinnedImage: "node:lts-alpine@sha256:abc123", |
| 306 | wantOK: true, |
| 307 | }, |
| 308 | { |
| 309 | name: "empty digest stored as-is", |
| 310 | image: "myimage:tag", |
| 311 | digest: "", |
| 312 | pinnedImage: "myimage:tag@", |
| 313 | wantOK: true, |
| 314 | }, |
| 315 | { |
| 316 | name: "empty pinned_image stored as-is", |
| 317 | image: "myimage:v1", |
| 318 | digest: "sha256:deadbeef", |
| 319 | pinnedImage: "", |
| 320 | wantOK: true, |
| 321 | }, |
| 322 | } |
| 323 | |
| 324 | for _, tt := range tests { |
| 325 | t.Run(tt.name, func(t *testing.T) { |
| 326 | tmpDir := testutil.TempDir(t, "test-*") |
| 327 | cache := NewActionCache(tmpDir) |
| 328 | cache.SetContainerPin(tt.image, tt.digest, tt.pinnedImage) |
| 329 | |
| 330 | pin, ok := cache.GetContainerPin(tt.image) |
| 331 | if ok != tt.wantOK { |
| 332 | t.Errorf("GetContainerPin returned ok=%v, want %v", ok, tt.wantOK) |
| 333 | } |
| 334 | if ok { |
| 335 | if pin.Digest != tt.digest { |
| 336 | t.Errorf("Digest: got %q, want %q", pin.Digest, tt.digest) |
| 337 | } |
| 338 | if pin.PinnedImage != tt.pinnedImage { |
| 339 | t.Errorf("PinnedImage: got %q, want %q", pin.PinnedImage, tt.pinnedImage) |
| 340 | } |
| 341 | } |
| 342 | }) |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | // TestActionCacheDeduplication tests that duplicate entries are removed |
| 347 | func TestActionCacheDeduplication(t *testing.T) { |
nothing calls this directly
no test coverage detected