Skip to content

Commit 7e4a085

Browse files
authored
Merge pull request moby#5341 from daghack/fix-flaky-secrets-test
frontend tests: add secondary sort on errors for more consistent rule check tests
2 parents e15601a + baecdec commit 7e4a085

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

frontend/dockerfile/dockerfile_lint_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,15 @@ ENV git_key=
191191
{
192192
RuleName: "SecretsUsedInArgOrEnv",
193193
Description: "Sensitive data should not be used in the ARG or ENV commands",
194-
Detail: `Do not use ARG or ENV instructions for sensitive data (ARG "super_duper_secret_token")`,
194+
Detail: `Do not use ARG or ENV instructions for sensitive data (ARG "auth")`,
195195
URL: "https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/",
196196
Level: 1,
197197
Line: 6,
198198
},
199199
{
200200
RuleName: "SecretsUsedInArgOrEnv",
201201
Description: "Sensitive data should not be used in the ARG or ENV commands",
202-
Detail: `Do not use ARG or ENV instructions for sensitive data (ARG "auth")`,
202+
Detail: `Do not use ARG or ENV instructions for sensitive data (ARG "super_duper_secret_token")`,
203203
URL: "https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/",
204204
Level: 1,
205205
Line: 6,
@@ -1388,6 +1388,9 @@ func checkUnmarshal(t *testing.T, sb integration.Sandbox, lintTest *lintTestPara
13881388
// sort by line number in ascending order
13891389
firstRange := lintResults.Warnings[i].Location.Ranges[0]
13901390
secondRange := lintResults.Warnings[j].Location.Ranges[0]
1391+
if firstRange.Start.Line == secondRange.Start.Line {
1392+
return lintResults.Warnings[i].Detail < lintResults.Warnings[j].Detail
1393+
}
13911394
return firstRange.Start.Line < secondRange.Start.Line
13921395
})
13931396
// Compare expectedLintWarning with actual lint results
@@ -1477,6 +1480,9 @@ func checkProgressStream(t *testing.T, sb integration.Sandbox, lintTest *lintTes
14771480
} else if len(w2.Range) == 0 {
14781481
return false
14791482
}
1483+
if w1.Range[0].Start.Line == w2.Range[0].Start.Line {
1484+
return string(w1.Short) < string(w2.Short)
1485+
}
14801486
return w1.Range[0].Start.Line < w2.Range[0].Start.Line
14811487
})
14821488
for i, w := range warnings {
@@ -1487,6 +1493,9 @@ func checkProgressStream(t *testing.T, sb integration.Sandbox, lintTest *lintTes
14871493
func checkLinterWarnings(t *testing.T, sb integration.Sandbox, lintTest *lintTestParams) {
14881494
t.Helper()
14891495
sort.Slice(lintTest.Warnings, func(i, j int) bool {
1496+
if lintTest.Warnings[i].Line == lintTest.Warnings[j].Line {
1497+
return lintTest.Warnings[i].Detail < lintTest.Warnings[j].Detail
1498+
}
14901499
return lintTest.Warnings[i].Line < lintTest.Warnings[j].Line
14911500
})
14921501

0 commit comments

Comments
 (0)