TestContainerPinCRUD verifies the Get/Set/Delete lifecycle for container pins.
(t *testing.T)
| 14 | |
| 15 | // TestContainerPinCRUD verifies the Get/Set/Delete lifecycle for container pins. |
| 16 | func TestContainerPinCRUD(t *testing.T) { |
| 17 | cache := NewActionCache(t.TempDir()) |
| 18 | |
| 19 | // Initially no pin. |
| 20 | _, ok := cache.GetContainerPin("node:lts-alpine") |
| 21 | assert.False(t, ok, "no pin expected before Set") |
| 22 | |
| 23 | // Set a pin. |
| 24 | cache.SetContainerPin("node:lts-alpine", "sha256:abc123", "node:lts-alpine@sha256:abc123") |
| 25 | pin, ok := cache.GetContainerPin("node:lts-alpine") |
| 26 | require.True(t, ok, "pin should exist after Set") |
| 27 | assert.Equal(t, "node:lts-alpine", pin.Image, "Image field") |
| 28 | assert.Equal(t, "sha256:abc123", pin.Digest, "Digest field") |
| 29 | assert.Equal(t, "node:lts-alpine@sha256:abc123", pin.PinnedImage, "PinnedImage field") |
| 30 | |
| 31 | // Overwrite with updated pin. |
| 32 | cache.SetContainerPin("node:lts-alpine", "sha256:updated", "node:lts-alpine@sha256:updated") |
| 33 | pin, ok = cache.GetContainerPin("node:lts-alpine") |
| 34 | require.True(t, ok, "pin should exist after update") |
| 35 | assert.Equal(t, "sha256:updated", pin.Digest, "updated Digest") |
| 36 | |
| 37 | // Delete the pin. |
| 38 | cache.DeleteContainerPin("node:lts-alpine") |
| 39 | _, ok = cache.GetContainerPin("node:lts-alpine") |
| 40 | assert.False(t, ok, "pin should be gone after Delete") |
| 41 | |
| 42 | // Deleting a non-existent pin is a no-op. |
| 43 | assert.NotPanics(t, func() { cache.DeleteContainerPin("nonexistent:latest") }, "delete non-existent should not panic") |
| 44 | } |
| 45 | |
| 46 | // TestContainerPinSaveLoad verifies that container pins survive a JSON round-trip. |
| 47 | func TestContainerPinSaveLoad(t *testing.T) { |
nothing calls this directly
no test coverage detected