@@ -9,99 +9,68 @@ import (
99
1010// TestActionPinsExist verifies that all action pinning entries exist
1111func TestActionPinsExist (t * testing.T ) {
12- expectedActions := []string {
13- "actions/checkout" ,
14- "actions/github-script" ,
15- "actions/upload-artifact" ,
16- "actions/download-artifact" ,
17- "actions/cache" ,
18- "actions/setup-node" ,
19- "actions/setup-python" ,
20- "actions/setup-go" ,
21- "actions/setup-java" ,
22- "actions/setup-dotnet" ,
23- "erlef/setup-beam" ,
24- "haskell-actions/setup" ,
25- "ruby/setup-ruby" ,
26- "astral-sh/setup-uv" ,
12+ // Read action pins from JSON file instead of hardcoded list
13+ actionPins := getActionPins ()
14+
15+ // Verify we have at least some pins loaded
16+ if len (actionPins ) == 0 {
17+ t .Fatal ("No action pins loaded from JSON file" )
2718 }
2819
29- actionPins := getActionPins ()
30- for _ , action := range expectedActions {
31- var pin ActionPin
32- found := false
33- for _ , p := range actionPins {
34- if p .Repo == action {
35- pin = p
36- found = true
37- break
38- }
39- }
40- if ! found {
41- t .Errorf ("Missing action pin for %s" , action )
20+ // Verify each pin has required fields
21+ for _ , pin := range actionPins {
22+ // Verify the pin has a repo
23+ if pin .Repo == "" {
24+ t .Errorf ("Action pin has empty Repo field" )
4225 continue
4326 }
4427
4528 // Verify the pin has a valid SHA (40 character hex string)
4629 if ! isValidSHA (pin .SHA ) {
47- t .Errorf ("Invalid SHA for %s: %s (expected 40-character hex string)" , action , pin .SHA )
30+ t .Errorf ("Invalid SHA for %s: %s (expected 40-character hex string)" , pin . Repo , pin .SHA )
4831 }
4932
5033 // Verify the pin has a version
5134 if pin .Version == "" {
52- t .Errorf ("Missing version for %s" , action )
35+ t .Errorf ("Missing version for %s" , pin . Repo )
5336 }
5437 }
5538}
5639
5740// TestGetActionPinReturnsValidSHA tests that GetActionPin returns valid SHA references
5841func TestGetActionPinReturnsValidSHA (t * testing.T ) {
59- tests := []struct {
60- repo string
61- wantSHA bool
62- }{
63- {"actions/checkout" , true },
64- {"actions/github-script" , true },
65- {"actions/upload-artifact" , true },
66- {"actions/download-artifact" , true },
67- {"actions/cache" , true },
68- {"actions/setup-node" , true },
69- {"actions/setup-python" , true },
70- {"actions/setup-go" , true },
71- {"actions/setup-java" , true },
72- {"actions/setup-dotnet" , true },
73- {"erlef/setup-beam" , true },
74- {"haskell-actions/setup" , true },
75- {"ruby/setup-ruby" , true },
76- {"astral-sh/setup-uv" , true },
42+ // Generate test cases dynamically from action pins JSON
43+ actionPins := getActionPins ()
44+
45+ if len (actionPins ) == 0 {
46+ t .Fatal ("No action pins loaded from JSON file" )
7747 }
7848
79- for _ , tt := range tests {
80- t .Run (tt . repo , func (t * testing.T ) {
81- result := GetActionPin (tt . repo )
49+ for _ , pin := range actionPins {
50+ t .Run (pin . Repo , func (t * testing.T ) {
51+ result := GetActionPin (pin . Repo )
8252
8353 // Check that the result contains a SHA (40-char hex after @ and before #)
8454 // Format is: repo@sha # version
8555 parts := strings .Split (result , "@" )
8656 if len (parts ) != 2 {
87- t .Errorf ("GetActionPin(%s) = %s, expected format repo@sha # version" , tt . repo , result )
57+ t .Errorf ("GetActionPin(%s) = %s, expected format repo@sha # version" , pin . Repo , result )
8858 return
8959 }
9060
9161 // Extract SHA (before the comment marker " # ")
9262 shaAndComment := parts [1 ]
9363 commentIdx := strings .Index (shaAndComment , " # " )
9464 if commentIdx == - 1 {
95- t .Errorf ("GetActionPin(%s) = %s, expected comment with version tag" , tt . repo , result )
65+ t .Errorf ("GetActionPin(%s) = %s, expected comment with version tag" , pin . Repo , result )
9666 return
9767 }
9868
9969 sha := shaAndComment [:commentIdx ]
10070
101- if tt .wantSHA {
102- if ! isValidSHA (sha ) {
103- t .Errorf ("GetActionPin(%s) = %s, expected SHA to be 40-char hex" , tt .repo , result )
104- }
71+ // All action pins should have valid SHAs
72+ if ! isValidSHA (sha ) {
73+ t .Errorf ("GetActionPin(%s) = %s, expected SHA to be 40-char hex" , pin .Repo , result )
10574 }
10675 })
10776 }
0 commit comments