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

Function TestActionCacheSaveLoad

pkg/workflow/action_cache_test.go:40–78  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

38}
39
40func TestActionCacheSaveLoad(t *testing.T) {
41 // Create temporary directory for testing
42 tmpDir := testutil.TempDir(t, "test-*")
43
44 // Create and populate cache
45 cache1 := NewActionCache(tmpDir)
46 cache1.Set("actions/checkout", "v5", "abc123")
47 cache1.Set("actions/setup-node", "v4", "def456")
48
49 // Save to disk
50 err := cache1.Save()
51 if err != nil {
52 t.Fatalf("Failed to save cache: %v", err)
53 }
54
55 // Verify file exists
56 cachePath := filepath.Join(tmpDir, ".github", "aw", CacheFileName)
57 if _, err := os.Stat(cachePath); os.IsNotExist(err) {
58 t.Fatalf("Cache file was not created at %s", cachePath)
59 }
60
61 // Load into new cache instance
62 cache2 := NewActionCache(tmpDir)
63 err = cache2.Load()
64 if err != nil {
65 t.Fatalf("Failed to load cache: %v", err)
66 }
67
68 // Verify entries were loaded
69 sha, found := cache2.Get("actions/checkout", "v5")
70 if !found || sha != "abc123" {
71 t.Errorf("Expected to find actions/checkout@v5 with SHA 'abc123', got '%s' (found=%v)", sha, found)
72 }
73
74 sha, found = cache2.Get("actions/setup-node", "v4")
75 if !found || sha != "def456" {
76 t.Errorf("Expected to find actions/setup-node@v6 with SHA 'def456', got '%s' (found=%v)", sha, found)
77 }
78}
79
80func TestActionCacheLoadNonExistent(t *testing.T) {
81 // Create temporary directory for testing

Callers

nothing calls this directly

Calls 7

SetMethod · 0.95
SaveMethod · 0.95
LoadMethod · 0.95
GetMethod · 0.95
TempDirFunction · 0.92
NewActionCacheFunction · 0.85
ErrorfMethod · 0.45

Tested by

no test coverage detected