Skip to content

Commit f7999fe

Browse files
authored
Merge pull request moby#5799 from tonistiigi/lint-error-combine
dockerfile: combine lint error testing into single variable
2 parents 31cb92f + 3382f72 commit f7999fe

File tree

1 file changed

+18
-27
lines changed

1 file changed

+18
-27
lines changed

frontend/dockerfile/dockerfile_lint_test.go

+18-27
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,8 @@ copy Dockerfile .
397397
Level: 1,
398398
},
399399
},
400-
StreamBuildErr: "failed to solve: lint violation found for rules: FromAsCasing",
401-
UnmarshalBuildErr: "lint violation found for rules: FromAsCasing",
402-
BuildErrLocation: 2,
400+
BuildErr: "lint violation found for rules: FromAsCasing",
401+
BuildErrLocation: 2,
403402
})
404403

405404
dockerfile = []byte(`#check=skip=all
@@ -418,9 +417,8 @@ copy Dockerfile .
418417
Level: 1,
419418
},
420419
},
421-
StreamBuildErr: "failed to solve: lint violation found for rules: FromAsCasing",
422-
UnmarshalBuildErr: "lint violation found for rules: FromAsCasing",
423-
BuildErrLocation: 2,
420+
BuildErr: "lint violation found for rules: FromAsCasing",
421+
BuildErrLocation: 2,
424422
FrontendAttrs: map[string]string{
425423
"build-arg:BUILDKIT_DOCKERFILE_CHECK": "skip=ConsistentInstructionCasing;error=true",
426424
},
@@ -858,9 +856,8 @@ BADCMD
858856
Line: 3,
859857
},
860858
},
861-
StreamBuildErr: "failed to solve: dockerfile parse error on line 4: unknown instruction: BADCMD",
862-
UnmarshalBuildErr: "dockerfile parse error on line 4: unknown instruction: BADCMD",
863-
BuildErrLocation: 4,
859+
BuildErr: "dockerfile parse error on line 4: unknown instruction: BADCMD",
860+
BuildErrLocation: 4,
864861
})
865862
}
866863

@@ -922,9 +919,8 @@ COPY Dockerfile .
922919
Line: 2,
923920
},
924921
},
925-
StreamBuildErr: "failed to solve: empty platform value from expression $BULIDPLATFORM (did you mean BUILDPLATFORM?)",
926-
UnmarshalBuildErr: "empty platform value from expression $BULIDPLATFORM (did you mean BUILDPLATFORM?)",
927-
BuildErrLocation: 2,
922+
BuildErr: "empty platform value from expression $BULIDPLATFORM (did you mean BUILDPLATFORM?)",
923+
BuildErrLocation: 2,
928924
})
929925

930926
osName := integration.UnixOrWindows("linux", "windows")
@@ -939,10 +935,7 @@ COPY Dockerfile .
939935
osName, osName, baseImg))
940936

941937
osStr := integration.UnixOrWindows("linux", "windows")
942-
streamBuildErr := fmt.Sprintf(
943-
"failed to solve: failed to parse platform %s/${MYARCH}: \"\" is an invalid component of \"%s/\": platform specifier component must match \"^[A-Za-z0-9_.-]+$\": invalid argument (did you mean MY_ARCH?)",
944-
osStr, osStr)
945-
unmarshalBuildErr := fmt.Sprintf(
938+
buildErr := fmt.Sprintf(
946939
"failed to parse platform %s/${MYARCH}: \"\" is an invalid component of \"%s/\": platform specifier component must match \"^[A-Za-z0-9_.-]+$\": invalid argument (did you mean MY_ARCH?)",
947940
osStr, osStr)
948941
checkLinterWarnings(t, sb, &lintTestParams{
@@ -957,9 +950,8 @@ COPY Dockerfile .
957950
Line: 4,
958951
},
959952
},
960-
StreamBuildErr: streamBuildErr,
961-
UnmarshalBuildErr: unmarshalBuildErr,
962-
BuildErrLocation: 4,
953+
BuildErr: buildErr,
954+
BuildErrLocation: 4,
963955
})
964956

965957
dockerfile = []byte(fmt.Sprintf(
@@ -1470,12 +1462,12 @@ func checkUnmarshal(t *testing.T, sb integration.Sandbox, lintTest *lintTestPara
14701462
lintResults, err := unmarshalLintResults(res)
14711463
require.NoError(t, err)
14721464

1473-
if lintTest.UnmarshalBuildErr == "" && lintTest.UnmarshalBuildErrRegexp == nil {
1465+
if lintTest.BuildErr == "" && lintTest.UnmarshalBuildErrRegexp == nil {
14741466
require.Nil(t, lintResults.Error)
14751467
} else {
14761468
require.NotNil(t, lintResults.Error)
1477-
if lintTest.UnmarshalBuildErr != "" {
1478-
require.Equal(t, lintTest.UnmarshalBuildErr, lintResults.Error.Message)
1469+
if lintTest.BuildErr != "" {
1470+
require.Equal(t, lintTest.BuildErr, lintResults.Error.Message)
14791471
} else if !lintTest.UnmarshalBuildErrRegexp.MatchString(lintResults.Error.Message) {
14801472
t.Fatalf("error %q does not match %q", lintResults.Error.Message, lintTest.UnmarshalBuildErrRegexp.String())
14811473
}
@@ -1562,14 +1554,14 @@ func checkProgressStream(t *testing.T, sb integration.Sandbox, lintTest *lintTes
15621554
dockerui.DefaultLocalNameContext: lintTest.TmpDir,
15631555
},
15641556
}, status)
1565-
if lintTest.StreamBuildErr == "" && lintTest.StreamBuildErrRegexp == nil {
1557+
if lintTest.BuildErr == "" && lintTest.StreamBuildErrRegexp == nil {
15661558
if err != nil {
15671559
t.Logf("expected no error, received: %v", err)
15681560
}
15691561
require.NoError(t, err)
15701562
} else {
1571-
if lintTest.StreamBuildErr != "" {
1572-
require.EqualError(t, err, lintTest.StreamBuildErr)
1563+
if lintTest.BuildErr != "" {
1564+
require.ErrorContains(t, err, lintTest.BuildErr)
15731565
} else if !lintTest.StreamBuildErrRegexp.MatchString(err.Error()) {
15741566
t.Fatalf("error %q does not match %q", err.Error(), lintTest.StreamBuildErrRegexp.String())
15751567
}
@@ -1695,9 +1687,8 @@ type lintTestParams struct {
16951687
DockerIgnore []byte
16961688
Warnings []expectedLintWarning
16971689
UnmarshalWarnings []expectedLintWarning
1698-
StreamBuildErr string
1690+
BuildErr string
16991691
StreamBuildErrRegexp *regexp.Regexp
1700-
UnmarshalBuildErr string
17011692
UnmarshalBuildErrRegexp *regexp.Regexp
17021693
BuildErrLocation int32
17031694
FrontendAttrs map[string]string

0 commit comments

Comments
 (0)