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

Function TestActionKeyVersionConsistency

pkg/cli/update_actions_test.go:30–73  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

28}
29
30func TestActionKeyVersionConsistency(t *testing.T) {
31 // This test ensures that when an action is updated, the key in the map
32 // is updated to match the new version, preventing key/version mismatches
33 // that would cause version comments to change on each build.
34
35 // Simulate the actions-lock.json structure using ActionCache
36 tmpDir := testutil.TempDir(t, "test-*")
37 cache := workflow.NewActionCache(tmpDir)
38 cache.Set("actions/checkout", "v5.0.0", "oldsha1234567890123456789012345678901234")
39
40 // Simulate an update to a newer version
41 oldVersion := "v5.0.0"
42 latestVersion := "v5.0.1"
43 latestSHA := "newsha1234567890123456789012345678901234"
44
45 // Apply the update logic from UpdateActions: delete old key, set new entry
46 cache.Delete("actions/checkout", oldVersion)
47 cache.Set("actions/checkout", latestVersion, latestSHA)
48
49 oldKey := "actions/checkout@v5.0.0"
50 newKey := "actions/checkout@v5.0.1"
51
52 // Verify the old key is gone
53 if _, exists := cache.Entries[oldKey]; exists {
54 t.Errorf("Old key %q should have been deleted", oldKey)
55 }
56
57 // Verify the new key exists
58 updatedEntry, exists := cache.Entries[newKey]
59 if !exists {
60 t.Errorf("New key %q should exist", newKey)
61 }
62
63 // Verify the entry has the correct version
64 if updatedEntry.Version != latestVersion {
65 t.Errorf("Entry version = %q, want %q", updatedEntry.Version, latestVersion)
66 }
67
68 // Most importantly: verify key and version field match
69 keyVersion := newKey[len("actions/checkout@"):]
70 if keyVersion != updatedEntry.Version {
71 t.Errorf("Key version %q does not match entry version %q", keyVersion, updatedEntry.Version)
72 }
73}
74
75func TestActionKeyVersionConsistencyInJSON(t *testing.T) {
76 // This test ensures that when actions-lock.json is saved to disk and reloaded,

Callers

nothing calls this directly

Calls 5

SetMethod · 0.95
DeleteMethod · 0.95
TempDirFunction · 0.92
NewActionCacheFunction · 0.92
ErrorfMethod · 0.45

Tested by

no test coverage detected