|
1 | 1 | package main |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "fmt" |
4 | 5 | "os" |
| 6 | + "path/filepath" |
| 7 | + "strings" |
5 | 8 | "testing" |
6 | 9 |
|
7 | 10 | "github.com/github/gh-actions-lock/internal/ghapi/httpmock" |
@@ -103,3 +106,56 @@ func TestValidateOutputFlags_VerifyConflicts(t *testing.T) { |
103 | 106 | }) |
104 | 107 | } |
105 | 108 | } |
| 109 | + |
| 110 | +func TestVerifyLocalReportsLocalActionsWithoutWriting(t *testing.T) { |
| 111 | + for _, extra := range [][]string{nil, {"--no-migrate-local-actions"}, {"--no-fix"}} { |
| 112 | + for _, jsonOut := range []bool{true, false} { |
| 113 | + t.Run(strings.Join(append(extra, fmt.Sprintf("json=%v", jsonOut)), " "), func(t *testing.T) { |
| 114 | + path := writeTempWorkflow(t, ` |
| 115 | +name: ci |
| 116 | +on: push |
| 117 | +jobs: |
| 118 | + test: |
| 119 | + runs-on: ubuntu-latest |
| 120 | + steps: |
| 121 | + - uses: tenant/internal@v1 |
| 122 | + - uses: ./my-action |
| 123 | + call: |
| 124 | + uses: ./.github/workflows/reusable.yml |
| 125 | +`, "tenant/internal@v1=sha1-"+tenantSHA) |
| 126 | + require.NoError(t, os.Mkdir(".git", 0o755)) |
| 127 | + require.NoError(t, os.Mkdir("my-action", 0o755)) |
| 128 | + require.NoError(t, os.WriteFile(filepath.Join("my-action", "action.yml"), []byte("runs:\n using: composite\n steps: []\n"), 0o644)) |
| 129 | + require.NoError(t, os.WriteFile(filepath.Join(".github", "workflows", "reusable.yml"), []byte("on: workflow_call\njobs:\n a:\n runs-on: ubuntu-latest\n steps:\n - run: echo\n"), 0o644)) |
| 130 | + before, err := os.ReadFile(path) |
| 131 | + require.NoError(t, err) |
| 132 | + lockBefore := readTempLockfilePins(t) |
| 133 | + |
| 134 | + args := append([]string{"--verify-local", "--no-interactive"}, extra...) |
| 135 | + if jsonOut { |
| 136 | + args = append(args, "--json=valid,findings") |
| 137 | + } |
| 138 | + stdout, stderr, err := runCommandWithHTTP(t, &httpmock.Registry{}, append(args, path)...) |
| 139 | + |
| 140 | + require.ErrorIs(t, err, errSilent) |
| 141 | + if jsonOut { |
| 142 | + assert.Contains(t, stdout, `"valid": false`) |
| 143 | + assert.Contains(t, stdout, `"category": "local-action"`) |
| 144 | + assert.Contains(t, stdout, `"severity": "error"`) |
| 145 | + } else { |
| 146 | + out := stdout + stderr |
| 147 | + assert.Contains(t, out, "local path actions") |
| 148 | + assert.Contains(t, out, "Run without --verify-local") |
| 149 | + assert.NotContains(t, out, "Migrated") |
| 150 | + } |
| 151 | + after, err := os.ReadFile(path) |
| 152 | + require.NoError(t, err) |
| 153 | + assert.Equal(t, string(before), string(after)) |
| 154 | + action, err := os.ReadFile(filepath.Join("my-action", "action.yml")) |
| 155 | + require.NoError(t, err) |
| 156 | + assert.NotContains(t, string(action), "$/") |
| 157 | + assert.Equal(t, lockBefore, readTempLockfilePins(t)) |
| 158 | + }) |
| 159 | + } |
| 160 | + } |
| 161 | +} |
0 commit comments