|
7 | 7 | "encoding/json" |
8 | 8 | "os" |
9 | 9 | "path/filepath" |
| 10 | + "runtime" |
10 | 11 | "testing" |
11 | 12 |
|
12 | | - "github.com/github/gh-aw/pkg/constants" |
13 | 13 | workflowlint "github.com/github/gh-aw/pkg/workflow/lint" |
14 | 14 | "github.com/stretchr/testify/assert" |
15 | 15 | "github.com/stretchr/testify/require" |
@@ -63,6 +63,26 @@ func TestCacheWriteOverrideCLI(t *testing.T) { |
63 | 63 | } |
64 | 64 |
|
65 | 65 | func TestLintCacheModeLiteralsCLI(t *testing.T) { |
| 66 | + if runtime.GOOS == "windows" { |
| 67 | + t.Skip("test binaries use a POSIX shell") |
| 68 | + } |
| 69 | + dir := actionlintTestDir(t) |
| 70 | + script := `#!/bin/sh |
| 71 | +if [ "$#" -eq 1 ] && [ "$1" = "--version" ]; then |
| 72 | + printf '1.7.12\n' |
| 73 | + exit 0 |
| 74 | +fi |
| 75 | +printf '%s\n' "$@" > "$ACTIONLINT_TEST_ARGS" |
| 76 | +printf '[]\n' |
| 77 | +` |
| 78 | + require.NoError(t, os.WriteFile(filepath.Join(dir, "actionlint"), []byte(script), 0o755)) |
| 79 | + t.Setenv("PATH", dir) |
| 80 | + argsPath := filepath.Join(dir, "args.txt") |
| 81 | + t.Setenv("ACTIONLINT_TEST_ARGS", argsPath) |
| 82 | + originalVersion, originalStats := actionlintVersion, actionlintStats |
| 83 | + actionlintVersion, actionlintStats = "", nil |
| 84 | + t.Cleanup(func() { actionlintVersion, actionlintStats = originalVersion, originalStats }) |
| 85 | + |
66 | 86 | for _, scope := range []string{"workflow", "job"} { |
67 | 87 | for _, test := range []struct { |
68 | 88 | name, mode string |
@@ -96,18 +116,25 @@ func TestLintCacheModeLiteralsCLI(t *testing.T) { |
96 | 116 | source += " cache-mode: " + test.mode + "\n" |
97 | 117 | } |
98 | 118 | source += " steps: [{run: echo data}]\n" |
99 | | - dir := actionlintTestDir(t) |
100 | | - // Docker actionlint runs as guest, so its non-sensitive fixture must be readable. |
101 | | - require.NoError(t, os.Chmod(dir, constants.DirPermPublic)) |
102 | 119 | file := filepath.Join(dir, "cache.yml") |
103 | | - require.NoError(t, os.WriteFile(file, []byte(source), constants.FilePermPublic)) |
104 | | - for _, args := range [][]string{{file}, {"--rules=cache-poisoning", file}} { |
| 120 | + require.NoError(t, os.WriteFile(file, []byte(source), 0o600)) |
| 121 | + for i, args := range [][]string{{file}, {"--rules=cache-poisoning", file}} { |
| 122 | + if i == 1 { |
| 123 | + require.NoError(t, os.Remove(argsPath)) |
| 124 | + } |
105 | 125 | cmd := NewLintCommand() |
106 | 126 | var output bytes.Buffer |
107 | 127 | cmd.SetOut(&output) |
108 | 128 | cmd.SetErr(&output) |
109 | 129 | cmd.SetArgs(args) |
110 | 130 | err := cmd.Execute() |
| 131 | + if i == 0 { |
| 132 | + _, statErr := os.Stat(argsPath) |
| 133 | + require.NoError(t, statErr, "default lint must invoke actionlint") |
| 134 | + } else { |
| 135 | + _, statErr := os.Stat(argsPath) |
| 136 | + require.True(t, os.IsNotExist(statErr), "selected rules must skip actionlint") |
| 137 | + } |
111 | 138 | if test.valid { |
112 | 139 | require.NoError(t, err, output.String()) |
113 | 140 | } else { |
|
0 commit comments