From 68c8224b96d750ec0e042c70461ec83d9fea404a Mon Sep 17 00:00:00 2001 From: Max Goltzsche Date: Wed, 30 Sep 2020 23:55:19 +0200 Subject: [PATCH] Add test with mismatching requirements.lock --- .gitignore | 1 + example/invalid-requirements-lock/Chart.yaml | 4 ++++ example/invalid-requirements-lock/chartref.yaml | 6 ++++++ .../invalid-requirements-lock/kustomization.yaml | 2 ++ example/invalid-requirements-lock/requirements.lock | 6 ++++++ example/invalid-requirements-lock/requirements.yaml | 4 ++++ pkg/helm/helm_test.go | 13 ++++++++++++- 7 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 example/invalid-requirements-lock/Chart.yaml create mode 100644 example/invalid-requirements-lock/chartref.yaml create mode 100644 example/invalid-requirements-lock/kustomization.yaml create mode 100644 example/invalid-requirements-lock/requirements.lock create mode 100644 example/invalid-requirements-lock/requirements.yaml diff --git a/.gitignore b/.gitignore index 33e0a9c..15ee342 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ example/**/charts example/**/.cache example/*/requirements.lock !example/cert-manager/requirements.lock +!example/invalid-requirements-lock/requirements.lock diff --git a/example/invalid-requirements-lock/Chart.yaml b/example/invalid-requirements-lock/Chart.yaml new file mode 100644 index 0000000..c4b2487 --- /dev/null +++ b/example/invalid-requirements-lock/Chart.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +description: example chart with mismatching requirements.lock +name: invalid-requirements-example +version: 0.1.0 diff --git a/example/invalid-requirements-lock/chartref.yaml b/example/invalid-requirements-lock/chartref.yaml new file mode 100644 index 0000000..c524cd0 --- /dev/null +++ b/example/invalid-requirements-lock/chartref.yaml @@ -0,0 +1,6 @@ +apiVersion: helm.kustomize.mgoltzsche.github.com/v1 +kind: ChartRenderer +metadata: + name: invalid-requirements-example + namespace: invalid-requirements-example-env +chart: . diff --git a/example/invalid-requirements-lock/kustomization.yaml b/example/invalid-requirements-lock/kustomization.yaml new file mode 100644 index 0000000..0f0da46 --- /dev/null +++ b/example/invalid-requirements-lock/kustomization.yaml @@ -0,0 +1,2 @@ +generators: +- chartref.yaml diff --git a/example/invalid-requirements-lock/requirements.lock b/example/invalid-requirements-lock/requirements.lock new file mode 100644 index 0000000..edf2f19 --- /dev/null +++ b/example/invalid-requirements-lock/requirements.lock @@ -0,0 +1,6 @@ +dependencies: +- name: cert-manager + repository: https://charts.jetstack.io + version: v1.0.2 +digest: sha256:a670f879168301db10f65ec15197ac7b29dc72486180ff68c3d5aec3fe53109b +generated: "2020-09-30T21:15:11.689897724Z" diff --git a/example/invalid-requirements-lock/requirements.yaml b/example/invalid-requirements-lock/requirements.yaml new file mode 100644 index 0000000..68ad07d --- /dev/null +++ b/example/invalid-requirements-lock/requirements.yaml @@ -0,0 +1,4 @@ +dependencies: +- name: cert-manager + version: 1.0.2 + repository: https://charts.jetstack.io \ No newline at end of file diff --git a/pkg/helm/helm_test.go b/pkg/helm/helm_test.go index df204be..9db6d2e 100644 --- a/pkg/helm/helm_test.go +++ b/pkg/helm/helm_test.go @@ -60,12 +60,23 @@ func TestRender(t *testing.T) { } } -func TestRenderReject(t *testing.T) { +func TestRenderRejectFileOutsideProjectDir(t *testing.T) { file := filepath.Join(currDir, "chartwithextvalues.yaml") err := render(t, file, currDir, &bytes.Buffer{}) require.Error(t, err, "render %s within %s", file, currDir) } +func TestRenderError(t *testing.T) { + for _, file := range []string{ + "../../example/invalid-requirements-lock/chartref.yaml", + } { + file = filepath.Join(currDir, file) + rootDir := filepath.Join(currDir, "..", "..") + err := render(t, file, rootDir, &bytes.Buffer{}) + require.Error(t, err, "render %s", file) + } +} + func render(t *testing.T, file, rootDir string, writer io.Writer) (err error) { log.SetFlags(0) f, err := os.Open(file)