-
Notifications
You must be signed in to change notification settings - Fork 173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: move lint e2e test to unit test #3334
Changes from all commits
44a0cbe
1ed51df
7d21204
f505433
bac67fa
83237b1
72c31ed
3af453b
0938fd9
3240e31
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,7 +119,6 @@ func templateZarfObj(zarfObj any, setVariables map[string]string) ([]PackageFind | |
return err | ||
} | ||
|
||
var unSetTemplates bool | ||
for key := range yamlTemplates { | ||
if deprecated { | ||
findings = append(findings, PackageFinding{ | ||
|
@@ -128,15 +127,12 @@ func templateZarfObj(zarfObj any, setVariables map[string]string) ([]PackageFind | |
}) | ||
} | ||
if _, present := setVariables[key]; !present { | ||
unSetTemplates = true | ||
findings = append(findings, PackageFinding{ | ||
Description: fmt.Sprintf("package template %s is not set and won't be evaluated during lint", key), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
Severity: SevWarn, | ||
}) | ||
} | ||
} | ||
if unSetTemplates { | ||
findings = append(findings, PackageFinding{ | ||
Description: lang.UnsetVarLintWarning, | ||
Severity: SevWarn, | ||
}) | ||
} | ||
for key, value := range setVariables { | ||
templateMap[fmt.Sprintf("%s%s###", templatePrefix, key)] = value | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,13 @@ package lint | |
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/zarf-dev/zarf/src/api/v1alpha1" | ||
"github.com/zarf-dev/zarf/src/config/lang" | ||
"github.com/zarf-dev/zarf/src/test/testutil" | ||
) | ||
|
||
func TestLintError(t *testing.T) { | ||
|
@@ -76,7 +78,7 @@ func TestFillObjTemplate(t *testing.T) { | |
expectedFindings := []PackageFinding{ | ||
{ | ||
Severity: SevWarn, | ||
Description: "There are templates that are not set and won't be evaluated during lint", | ||
Description: "package template KEY3 is not set and won't be evaluated during lint", | ||
}, | ||
{ | ||
Severity: SevWarn, | ||
|
@@ -93,3 +95,67 @@ func TestFillObjTemplate(t *testing.T) { | |
require.ElementsMatch(t, expectedFindings, findings) | ||
require.Equal(t, expectedComponent, component) | ||
} | ||
|
||
func TestLintPackageWithImports(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In an ideal world we would testing more cases which are smaller. But this makes sense as an iterative step in the right direction. |
||
ZarfSchema = testutil.LoadSchema(t, "../../../zarf.schema.json") | ||
setVariables := map[string]string{ | ||
"BUSYBOX_IMAGE": "latest", | ||
} | ||
ctx := context.Background() | ||
findings := []PackageFinding{ | ||
// unset exists in both the root and imported package | ||
{ | ||
YqPath: "", | ||
Description: "package template UNSET is not set and won't be evaluated during lint", | ||
Item: "", | ||
PackageNameOverride: "linted-import", | ||
PackagePathOverride: "linted-import", | ||
Severity: SevWarn, | ||
}, | ||
{ | ||
YqPath: "", | ||
Description: "package template UNSET is not set and won't be evaluated during lint", | ||
Item: "", | ||
PackageNameOverride: "lint", | ||
PackagePathOverride: ".", | ||
Severity: SevWarn, | ||
}, | ||
// Test imported skeleton package lints properly | ||
{ | ||
YqPath: ".components.[0].images.[0]", | ||
Description: "Image not pinned with digest", | ||
Item: "ghcr.io/zarf-dev/doom-game:0.0.1", | ||
PackageNameOverride: "dos-games", | ||
PackagePathOverride: "oci://ghcr.io/zarf-dev/packages/dos-games:1.1.0", | ||
Severity: SevWarn, | ||
}, | ||
// Test local import lints properly | ||
{ | ||
YqPath: ".components.[1].images.[0]", | ||
Description: "Image not pinned with digest", | ||
Item: "busybox:latest", | ||
PackageNameOverride: "linted-import", | ||
PackagePathOverride: "linted-import", | ||
Severity: SevWarn, | ||
}, | ||
// Test flavors | ||
{ | ||
YqPath: ".components.[4].images.[0]", | ||
Description: "Image not pinned with digest", | ||
Item: "image-in-good-flavor-component:unpinned", | ||
PackageNameOverride: "lint", | ||
PackagePathOverride: ".", | ||
Severity: SevWarn, | ||
}, | ||
} | ||
cwd, err := os.Getwd() | ||
require.NoError(t, err) | ||
// TODO @austinabro321: remove this and parallelize the test once changing the working directory is no longer required | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense keeping the scope of changes manageable. |
||
defer func() { | ||
require.NoError(t, os.Chdir(cwd)) | ||
}() | ||
err = Validate(ctx, "testdata/lint-with-imports", "good-flavor", setVariables) | ||
var lintErr *LintError | ||
require.ErrorAs(t, err, &lintErr) | ||
require.ElementsMatch(t, findings, lintErr.Findings) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
kind: ZarfPackageConfig | ||
metadata: | ||
name: lint | ||
|
||
components: | ||
- name: import-test | ||
import: | ||
path: linted-import | ||
|
||
- name: full-repo | ||
images: | ||
- busybox@sha256:3fbc632167424a6d997e74f52b878d7cc478225cffac6bc977eedfe51c7f4e79 | ||
- busybox:###ZARF_PKG_TMPL_UNSET### | ||
|
||
- name: oci-games-url | ||
import: | ||
path: linted-import | ||
|
||
- name: import-bad-flavor | ||
only: | ||
flavor: bad-flavor | ||
images: | ||
- image-in-bad-flavor-component:unpinned | ||
|
||
- name: import-good-flavor | ||
only: | ||
flavor: good-flavor | ||
images: | ||
- image-in-good-flavor-component:unpinned |
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shoving this into this PR. We don't do ironbank things anymore in Zarf, no reason to keep this around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍