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

Function TestActionCacheSortedEntries

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

Source from the content-addressed store, hash-verified

133}
134
135func TestActionCacheSortedEntries(t *testing.T) {
136 // Create temporary directory for testing
137 tmpDir := testutil.TempDir(t, "test-*")
138
139 // Create cache and add entries in non-alphabetical order
140 cache := NewActionCache(tmpDir)
141 cache.Set("zzz/last-action", "v1", "sha111")
142 cache.Set("actions/checkout", "v5", "sha222")
143 cache.Set("mmm/middle-action", "v2", "sha333")
144 cache.Set("actions/setup-node", "v4", "sha444")
145 cache.Set("aaa/first-action", "v3", "sha555")
146
147 // Save to disk
148 err := cache.Save()
149 if err != nil {
150 t.Fatalf("Failed to save cache: %v", err)
151 }
152
153 // Read the file content
154 cachePath := filepath.Join(tmpDir, ".github", "aw", CacheFileName)
155 data, err := os.ReadFile(cachePath)
156 if err != nil {
157 t.Fatalf("Failed to read cache file: %v", err)
158 }
159
160 content := string(data)
161
162 // Verify that entries appear in alphabetical order by checking their positions
163 entries := []string{
164 "aaa/first-action@v3",
165 "actions/checkout@v5",
166 "actions/setup-node@v4",
167 "mmm/middle-action@v2",
168 "zzz/last-action@v1",
169 }
170
171 lastPos := -1
172 for _, entry := range entries {
173 pos := indexOf(content, entry)
174 if pos == -1 {
175 t.Errorf("Entry %s not found in cache file", entry)
176 continue
177 }
178 if pos < lastPos {
179 t.Errorf("Entry %s appears before previous entry (not sorted)", entry)
180 }
181 lastPos = pos
182 }
183
184 // Also verify the file is valid JSON
185 var loadedCache ActionCache
186 err = json.Unmarshal(data, &loadedCache)
187 if err != nil {
188 t.Fatalf("Saved cache is not valid JSON: %v", err)
189 }
190
191 // Verify all entries are present
192 if len(loadedCache.Entries) != 5 {

Callers

nothing calls this directly

Calls 6

SetMethod · 0.95
SaveMethod · 0.95
TempDirFunction · 0.92
NewActionCacheFunction · 0.85
indexOfFunction · 0.70
ErrorfMethod · 0.45

Tested by

no test coverage detected