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

Function TestMarshalActionsLockSorted

pkg/cli/update_command_test.go:794–844  ·  view source on GitHub ↗

TestMarshalActionsLockSorted tests that the actions lock marshaling produces sorted output using the ActionCache.Save helper.

(t *testing.T)

Source from the content-addressed store, hash-verified

792// TestMarshalActionsLockSorted tests that the actions lock marshaling produces sorted output
793// using the ActionCache.Save helper.
794func TestMarshalActionsLockSorted(t *testing.T) {
795 tmpDir := testutil.TempDir(t, "test-*")
796
797 cache := workflow.NewActionCache(tmpDir)
798
799 // Add entries in non-alphabetical order
800 cache.Set("zebra/action", "v1", "abc123")
801 cache.Set("actions/checkout", "v5", "def456")
802
803 // Save to disk
804 if err := cache.Save(); err != nil {
805 t.Fatalf("Expected no error saving cache, got: %v", err)
806 }
807
808 // Read the file back
809 data, err := os.ReadFile(filepath.Join(tmpDir, ".github", "aw", "actions-lock.json"))
810 if err != nil {
811 t.Fatalf("Expected to read saved file, got: %v", err)
812 }
813
814 result := string(data)
815
816 // Check that actions/checkout comes before zebra/action (sorted output)
817 checkoutIdx := strings.Index(result, "actions/checkout")
818 zebraIdx := strings.Index(result, "zebra/action")
819
820 if checkoutIdx == -1 || zebraIdx == -1 {
821 t.Errorf("Expected both actions in output, got:\n%s", result)
822 }
823
824 if checkoutIdx > zebraIdx {
825 t.Errorf("Expected actions/checkout to appear before zebra/action in sorted output")
826 }
827
828 // Check JSON structure
829 if !strings.Contains(result, `"entries": {`) {
830 t.Error("Expected 'entries' key in JSON output")
831 }
832
833 if !strings.Contains(result, `"repo": "actions/checkout"`) {
834 t.Error("Expected actions/checkout repo in output")
835 }
836
837 if !strings.Contains(result, `"version": "v5"`) {
838 t.Error("Expected v5 version in output")
839 }
840
841 if !strings.Contains(result, `"sha": "def456"`) {
842 t.Error("Expected def456 SHA in output")
843 }
844}
845
846// TestGetActionSHAForTag tests that we can look up action SHAs (requires network)
847func TestGetActionSHAForTag(t *testing.T) {

Callers

nothing calls this directly

Calls 6

SetMethod · 0.95
SaveMethod · 0.95
TempDirFunction · 0.92
NewActionCacheFunction · 0.92
ErrorfMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected