Skip to content

Commit

Permalink
replace test
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Abro <[email protected]>
  • Loading branch information
AustinAbro321 committed Dec 16, 2024
1 parent 6c86967 commit 44a0cbe
Show file tree
Hide file tree
Showing 6 changed files with 252 additions and 34 deletions.
66 changes: 33 additions & 33 deletions examples/helm-charts/zarf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,50 @@ components:
- name: demo-helm-charts
required: true
charts:
# Charts are organized in a list with unique chart names per component - note that a Zarf chart name does not need to match the chart name in a Chart.yaml
- name: podinfo-local
version: 6.4.0
namespace: podinfo-from-local-chart
# In this case `localPath` will load the podinfo chart that is located in the `chart` directory
localPath: chart
valuesFiles:
- values.yaml
# Variables are used to override the default values in the chart
# This can be overridden by the user at deployment time with the `--set` flag
variables:
- name: REPLICA_COUNT
description: "Override the number of pod replicas"
path: replicaCount
# # Charts are organized in a list with unique chart names per component - note that a Zarf chart name does not need to match the chart name in a Chart.yaml
# - name: podinfo-local
# version: 6.4.0
# namespace: podinfo-from-local-chart
# # In this case `localPath` will load the podinfo chart that is located in the `chart` directory
# localPath: chart
# valuesFiles:
# - values.yaml
# # Variables are used to override the default values in the chart
# # This can be overridden by the user at deployment time with the `--set` flag
# variables:
# - name: REPLICA_COUNT
# description: "Override the number of pod replicas"
# path: replicaCount

- name: podinfo-oci
version: 6.4.0
namespace: podinfo-from-oci
# In this case `url` will load the helm chart located in the podinfo OCI repository
url: oci://ghcr.io/stefanprodan/charts/podinfo
valuesFiles:
- values.yaml
# - name: podinfo-oci
# version: 6.4.0
# namespace: podinfo-from-oci
# # In this case `url` will load the helm chart located in the podinfo OCI repository
# url: oci://ghcr.io/stefanprodan/charts/podinfo@main
# valuesFiles:
# - values.yaml

- name: podinfo-git
version: 6.4.0
namespace: podinfo-from-git
# In this case `url` will load the helm chart located in the podinfo git repository
url: https://github.com/stefanprodan/podinfo.git
url: https://github.com/stefanprodan/podinfo.git@refs/heads/master
# By default git will look in the root of the git repository but you can define a sub directory with `gitPath`
gitPath: charts/podinfo
valuesFiles:
- values.yaml

- name: podinfo-repo
version: 6.4.0
namespace: podinfo-from-repo
# In this case `url` will load the helm chart located in the podinfo helm repository
url: https://stefanprodan.github.io/podinfo
# By default the chart `name` will be what is used to search a repository but since Zarf chart names must be unique per-component you can override this with `repoName`
repoName: podinfo
# By default the release name will be the chart name, but you can override this with the `releaseName` key
releaseName: cool-release-name
valuesFiles:
- values.yaml
# - name: podinfo-repo
# version: 6.4.0
# namespace: podinfo-from-repo
# # In this case `url` will load the helm chart located in the podinfo helm repository
# url: https://stefanprodan.github.io/podinfo
# # By default the chart `name` will be what is used to search a repository but since Zarf chart names must be unique per-component you can override this with `repoName`
# repoName: podinfo
# # By default the release name will be the chart name, but you can override this with the `releaseName` key
# releaseName: cool-release-name
# valuesFiles:
# - values.yaml
images:
- ghcr.io/stefanprodan/podinfo:6.4.0
# This is the cosign signature for the podinfo image for image signature verification
Expand Down
142 changes: 142 additions & 0 deletions src/pkg/lint/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"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) {
Expand Down Expand Up @@ -93,3 +94,144 @@ func TestFillObjTemplate(t *testing.T) {
require.ElementsMatch(t, expectedFindings, findings)
require.Equal(t, expectedComponent, component)
}

func TestLintPackageWithImports(t *testing.T) {
ZarfSchema = testutil.LoadSchema(t, "../../../zarf.schema.json")
setVariables := map[string]string{
"BUSYBOX_IMAGE": "latest",
}
ctx := context.Background()
findings := []PackageFinding{
{
YqPath: "",
Description: "There are templates that are not set and won't be evaluated during lint",
Item: "",
PackageNameOverride: "linted-import",
PackagePathOverride: "linted-import",
Severity: SevWarn,
},
{
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,
},
{
YqPath: ".components.[1].images.[0]",
Description: "Image not pinned with digest",
Item: "registry.com:9001/whatever/image:latest",
PackageNameOverride: "linted-import",
PackagePathOverride: "linted-import",
Severity: SevWarn,
},
{
YqPath: ".components.[1].images.[2]",
Description: "Image not pinned with digest",
Item: "busybox:latest",
PackageNameOverride: "linted-import",
PackagePathOverride: "linted-import",
Severity: SevWarn,
},
{
YqPath: "",
Description: "There are templates that are not set and won't be evaluated during lint",
Item: "",
PackageNameOverride: "lint",
PackagePathOverride: ".",
Severity: SevWarn,
},
{
YqPath: "",
Description: `Package template "WHATEVER_IMAGE" is using the deprecated syntax ###ZARF_PKG_VAR_WHATEVER_IMAGE###. This will be removed in Zarf v1.0.0. Please update to ###ZARF_PKG_TMPL_WHATEVER_IMAGE###.`,
Item: "",
PackageNameOverride: "lint",
PackagePathOverride: ".",
Severity: SevWarn,
},
{
YqPath: "",
Description: "There are templates that are not set and won't be evaluated during lint",
Item: "",
PackageNameOverride: "lint",
PackagePathOverride: ".",
Severity: SevWarn,
},
{
YqPath: ".components.[2].repos.[0]",
Description: "Unpinned repository",
Item: "https://github.com/zarf-dev/zarf-public-test.git",
PackageNameOverride: "lint",
PackagePathOverride: ".",
Severity: SevWarn,
},
{
YqPath: ".components.[2].repos.[2]",
Description: "Unpinned repository",
Item: "https://gitlab.com/gitlab-org/build/omnibus-mirror/pcre2/-/tree/vreverse?ref_type=heads",
PackageNameOverride: "lint",
PackagePathOverride: ".",
Severity: SevWarn,
},
{
YqPath: ".components.[2].images.[0]",
Description: "Image not pinned with digest",
Item: "registry.com:9001/whatever/image:1.0.0",
PackageNameOverride: "lint",
PackagePathOverride: ".",
Severity: SevWarn,
},
{
YqPath: ".components.[2].images.[3]",
Description: "Image not pinned with digest",
Item: "busybox:latest",
PackageNameOverride: "lint",
PackagePathOverride: ".",
Severity: SevWarn,
},
{
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,
},
{
YqPath: ".components.[6].images.[0]",
Description: "Image not pinned with digest",
Item: "image-in-good-flavor-component:unpinned",
PackageNameOverride: "lint",
PackagePathOverride: ".",
Severity: SevWarn,
},
{
YqPath: ".components.[0].import",
Description: "Additional property not-path is not allowed",
Item: "",
PackageNameOverride: "",
PackagePathOverride: "",
Severity: SevErr,
},
{
YqPath: ".metadata",
Description: "Additional property description1 is not allowed",
Item: "",
PackageNameOverride: "",
PackagePathOverride: "",
Severity: SevErr,
},
}
// cwd, err := os.Getwd()
// require.NoError(t, err)
// err = os.Chdir(filepath.Join("testdata", "lint-with-templates"))
// require.NoError(t, err)
// 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)
}
2 changes: 1 addition & 1 deletion src/pkg/lint/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func TestValidatePackageSchema(t *testing.T) {
}
cwd, err := os.Getwd()
require.NoError(t, err)
err = os.Chdir(filepath.Join("testdata", "package-with-templates"))
err = os.Chdir(filepath.Join("testdata", "lint-with-templates"))
require.NoError(t, err)
defer func() {
require.NoError(t, os.Chdir(cwd))
Expand Down
23 changes: 23 additions & 0 deletions src/pkg/lint/testdata/lint-with-imports/linted-import/zarf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
kind: ZarfPackageConfig
metadata:
name: linted-import
description: Testing bad yaml imported

variables:
- name: BUSYBOX_IMAGE
description: "whatever"

components:
- name: dont-care

- name: import-test
images:
- registry.com:9001/whatever/image:latest
- busybox@sha256:3fbc632167424a6d997e74f52b878d7cc478225cffac6bc977eedfe51c7f4e79
- busybox:###ZARF_PKG_TMPL_BUSYBOX_IMAGE###
- busybox:###ZARF_PKG_TMPL_UNSET###

- name: oci-games-url
import:
url: oci://ghcr.io/zarf-dev/packages/dos-games:1.1.0
name: baseline
52 changes: 52 additions & 0 deletions src/pkg/lint/testdata/lint-with-imports/zarf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
kind: ZarfPackageConfig
metadata:
name: lint
description1: Testing bad yaml

components:
- name: first-test-component
import:
not-path: packages/distros/k3s

- name: import-test
import:
path: linted-import

- name: full-repo
repos:
- https://github.com/zarf-dev/zarf-public-test.git
- https://dev.azure.com/defenseunicorns/zarf-public-test/_git/[email protected]
- https://gitlab.com/gitlab-org/build/omnibus-mirror/pcre2/-/tree/vreverse?ref_type=heads
images:
- registry.com:9001/whatever/image:1.0.0
- busybox@sha256:3fbc632167424a6d997e74f52b878d7cc478225cffac6bc977eedfe51c7f4e79
- busybox:###ZARF_PKG_VAR_WHATEVER_IMAGE###
- busybox:###ZARF_PKG_TMPL_BUSYBOX_IMAGE###
- ubuntu:###ZARF_PKG_TMPL_UBUNTU_IMAGE###
files:
- source: https://github.com/k3s-io/k3s/releases/download/v1.28.2+k3s1/k3s
shasum: 2f041d37a2c6d54d53e106e1c7713bc48f806f3919b0d9e092f5fcbdc55b41cf
target: src/
- source: file-without-shasum.txt
target: src/

- name: oci-games-url
import:
url: oci://ghcr.io/zarf-dev/packages/dos-games:1.1.0
name: baseline

- 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
1 change: 1 addition & 0 deletions src/pkg/lint/testdata/package-with-templates/zarf.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
kind: ZarfPackageConfig
# Tests that the schema regex validation happen after templating
metadata:
name: "###ZARF_PKG_VAR_PACKAGE_NAME###"
components:
Expand Down

0 comments on commit 44a0cbe

Please sign in to comment.