TestContainerPinSaveLoad verifies that container pins survive a JSON round-trip.
(t *testing.T)
| 45 | |
| 46 | // TestContainerPinSaveLoad verifies that container pins survive a JSON round-trip. |
| 47 | func TestContainerPinSaveLoad(t *testing.T) { |
| 48 | tmpDir := testutil.TempDir(t, "container-pin-*") |
| 49 | |
| 50 | cache := NewActionCache(tmpDir) |
| 51 | cache.Set("actions/checkout", "v5", "sha1") |
| 52 | cache.SetContainerPin("node:lts-alpine", "sha256:abc123", "node:lts-alpine@sha256:abc123") |
| 53 | cache.SetContainerPin("alpine:latest", "sha256:def456", "alpine:latest@sha256:def456") |
| 54 | |
| 55 | require.NoError(t, cache.Save(), "Save should succeed") |
| 56 | |
| 57 | // Reload from disk. |
| 58 | cache2 := NewActionCache(tmpDir) |
| 59 | require.NoError(t, cache2.Load(), "Load should succeed") |
| 60 | |
| 61 | // Action entry should be preserved. |
| 62 | sha, ok := cache2.Get("actions/checkout", "v5") |
| 63 | require.True(t, ok, "action entry should be loaded") |
| 64 | assert.Equal(t, "sha1", sha, "SHA should match") |
| 65 | |
| 66 | // Container pins should be preserved. |
| 67 | pin, ok := cache2.GetContainerPin("node:lts-alpine") |
| 68 | require.True(t, ok, "node pin should be loaded") |
| 69 | assert.Equal(t, "sha256:abc123", pin.Digest, "node digest") |
| 70 | assert.Equal(t, "node:lts-alpine@sha256:abc123", pin.PinnedImage, "node pinned image") |
| 71 | |
| 72 | pin, ok = cache2.GetContainerPin("alpine:latest") |
| 73 | require.True(t, ok, "alpine pin should be loaded") |
| 74 | assert.Equal(t, "sha256:def456", pin.Digest, "alpine digest") |
| 75 | } |
| 76 | |
| 77 | // TestContainerPinBackwardCompatibility verifies that loading an existing |
| 78 | // actions-lock.json without a container_pins section returns an empty map |
nothing calls this directly
no test coverage detected