TestActionCacheSaveWithContainerPinsOnly verifies that a cache with no Entries but with ContainerPins is still written to disk (not treated as "empty").
(t *testing.T)
| 259 | // TestActionCacheSaveWithContainerPinsOnly verifies that a cache with no Entries |
| 260 | // but with ContainerPins is still written to disk (not treated as "empty"). |
| 261 | func TestActionCacheSaveWithContainerPinsOnly(t *testing.T) { |
| 262 | tmpDir := testutil.TempDir(t, "test-*") |
| 263 | cache := NewActionCache(tmpDir) |
| 264 | |
| 265 | // Add a container pin without any action entries |
| 266 | cache.SetContainerPin("node:lts-alpine", "sha256:abc123", "node:lts-alpine@sha256:abc123") |
| 267 | |
| 268 | if err := cache.Save(); err != nil { |
| 269 | t.Fatalf("Failed to save cache with container pins only: %v", err) |
| 270 | } |
| 271 | |
| 272 | // File should exist because ContainerPins is non-empty |
| 273 | cachePath := filepath.Join(tmpDir, ".github", "aw", CacheFileName) |
| 274 | if _, err := os.Stat(cachePath); os.IsNotExist(err) { |
| 275 | t.Error("Cache file should exist when ContainerPins is non-empty, even if Entries is empty") |
| 276 | } |
| 277 | |
| 278 | // Reload and confirm the pin round-trips correctly |
| 279 | reloaded := NewActionCache(tmpDir) |
| 280 | if err := reloaded.Load(); err != nil { |
| 281 | t.Fatalf("Failed to reload cache: %v", err) |
| 282 | } |
| 283 | pin, ok := reloaded.GetContainerPin("node:lts-alpine") |
| 284 | if !ok { |
| 285 | t.Fatal("Container pin should have been reloaded") |
| 286 | } |
| 287 | if pin.Digest != "sha256:abc123" { |
| 288 | t.Errorf("Expected digest sha256:abc123, got %s", pin.Digest) |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | // TestSetContainerPinEdgeCases verifies SetContainerPin behaviour with edge case inputs. |
| 293 | func TestSetContainerPinEdgeCases(t *testing.T) { |
nothing calls this directly
no test coverage detected