Skip to content

Commit ef52167

Browse files
pelikhanCopilot
andauthored
Remove Docker dependency from cache-mode lint test (#80157)
* Initial plan * Isolate cache mode lint tests from Docker Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --------- Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent c6a33a6 commit ef52167

1 file changed

Lines changed: 33 additions & 6 deletions

File tree

‎pkg/cli/lint_cache_mode_test.go‎

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
"encoding/json"
88
"os"
99
"path/filepath"
10+
"runtime"
1011
"testing"
1112

12-
"github.com/github/gh-aw/pkg/constants"
1313
workflowlint "github.com/github/gh-aw/pkg/workflow/lint"
1414
"github.com/stretchr/testify/assert"
1515
"github.com/stretchr/testify/require"
@@ -63,6 +63,26 @@ func TestCacheWriteOverrideCLI(t *testing.T) {
6363
}
6464

6565
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+
6686
for _, scope := range []string{"workflow", "job"} {
6787
for _, test := range []struct {
6888
name, mode string
@@ -96,18 +116,25 @@ func TestLintCacheModeLiteralsCLI(t *testing.T) {
96116
source += " cache-mode: " + test.mode + "\n"
97117
}
98118
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))
102119
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+
}
105125
cmd := NewLintCommand()
106126
var output bytes.Buffer
107127
cmd.SetOut(&output)
108128
cmd.SetErr(&output)
109129
cmd.SetArgs(args)
110130
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+
}
111138
if test.valid {
112139
require.NoError(t, err, output.String())
113140
} else {

0 commit comments

Comments
 (0)