| 38 | } |
| 39 | |
| 40 | func 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 | |
| 80 | func TestActionCacheLoadNonExistent(t *testing.T) { |
| 81 | // Create temporary directory for testing |