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

Function TestExtractActionsFromLockFile

pkg/workflow/action_sha_checker_test.go:14–73  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestExtractActionsFromLockFile(t *testing.T) {
15 // Create a temporary lock file with test content
16 tmpDir := testutil.TempDir(t, "test-*")
17 lockFile := filepath.Join(tmpDir, "test.lock.yml")
18
19 lockContent := `# gh-aw-metadata: {"schema_version":"v1"}
20name: Test Workflow
21on: push
22jobs:
23 test:
24 runs-on: ubuntu-latest
25 steps:
26 - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
27 - uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f
28 - name: Run tests
29 run: npm test
30 - uses: github/codeql-action/upload-sarif@ab2e54f42aa112ff08704159b88a57517f6f0ebb
31`
32
33 if err := os.WriteFile(lockFile, []byte(lockContent), 0644); err != nil {
34 t.Fatalf("Failed to create test lock file: %v", err)
35 }
36
37 // Extract actions
38 actions, err := ExtractActionsFromLockFile(lockFile)
39 if err != nil {
40 t.Fatalf("ExtractActionsFromLockFile failed: %v", err)
41 }
42
43 // Verify we extracted the expected actions
44 if len(actions) != 3 {
45 t.Errorf("Expected 3 actions, got %d", len(actions))
46 }
47
48 // Check that we have the expected repositories
49 expectedRepos := map[string]bool{
50 "actions/checkout": false,
51 "actions/setup-node": false,
52 "github/codeql-action/upload-sarif": false,
53 }
54
55 for _, action := range actions {
56 if _, exists := expectedRepos[action.Repo]; exists {
57 expectedRepos[action.Repo] = true
58 }
59 }
60
61 for repo, found := range expectedRepos {
62 if !found {
63 t.Errorf("Expected to find action %s, but it was not extracted", repo)
64 }
65 }
66
67 // Verify SHA format
68 for _, action := range actions {
69 if len(action.SHA) != 40 {
70 t.Errorf("Expected SHA to be 40 characters, got %d for %s", len(action.SHA), action.Repo)
71 }

Callers

nothing calls this directly

Calls 3

TempDirFunction · 0.92
ErrorfMethod · 0.45

Tested by

no test coverage detected