MCPcopy Create free account
hub / github.com/github/gh-aw / TestActionCacheSaveWithContainerPinsOnly

Function TestActionCacheSaveWithContainerPinsOnly

pkg/workflow/action_cache_test.go:261–290  ·  view source on GitHub ↗

TestActionCacheSaveWithContainerPinsOnly verifies that a cache with no Entries but with ContainerPins is still written to disk (not treated as "empty").

(t *testing.T)

Source from the content-addressed store, hash-verified

259// TestActionCacheSaveWithContainerPinsOnly verifies that a cache with no Entries
260// but with ContainerPins is still written to disk (not treated as "empty").
261func 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.
293func TestSetContainerPinEdgeCases(t *testing.T) {

Callers

nothing calls this directly

Calls 8

SetContainerPinMethod · 0.95
SaveMethod · 0.95
LoadMethod · 0.95
GetContainerPinMethod · 0.95
TempDirFunction · 0.92
NewActionCacheFunction · 0.85
ErrorMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected