Skip to content

Commit

Permalink
Add test with mismatching requirements.lock
Browse files Browse the repository at this point in the history
  • Loading branch information
mgoltzsche committed Sep 30, 2020
1 parent 2a0356f commit 68c8224
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ example/**/charts
example/**/.cache
example/*/requirements.lock
!example/cert-manager/requirements.lock
!example/invalid-requirements-lock/requirements.lock
4 changes: 4 additions & 0 deletions example/invalid-requirements-lock/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
description: example chart with mismatching requirements.lock
name: invalid-requirements-example
version: 0.1.0
6 changes: 6 additions & 0 deletions example/invalid-requirements-lock/chartref.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: helm.kustomize.mgoltzsche.github.com/v1
kind: ChartRenderer
metadata:
name: invalid-requirements-example
namespace: invalid-requirements-example-env
chart: .
2 changes: 2 additions & 0 deletions example/invalid-requirements-lock/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
generators:
- chartref.yaml
6 changes: 6 additions & 0 deletions example/invalid-requirements-lock/requirements.lock
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 4 additions & 0 deletions example/invalid-requirements-lock/requirements.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dependencies:
- name: cert-manager
version: 1.0.2
repository: https://charts.jetstack.io
13 changes: 12 additions & 1 deletion pkg/helm/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 68c8224

Please sign in to comment.