From e7b7c77a0284191319af047d86f8f59f58b92db9 Mon Sep 17 00:00:00 2001 From: Kevin Labesse Date: Thu, 21 Mar 2019 11:59:37 +0100 Subject: [PATCH] unit test Signed-off-by: Kevin Labesse --- cmd/helm/install_test.go | 11 ++++++++ .../testcharts/alpine-app-version/Chart.yaml | 7 +++++ .../testcharts/alpine-app-version/README.md | 13 +++++++++ .../alpine-app-version/extra_values.yaml | 2 ++ .../alpine-app-version/more_values.yaml | 2 ++ .../templates/alpine-pod.yaml | 27 +++++++++++++++++++ .../testcharts/alpine-app-version/values.yaml | 2 ++ cmd/helm/upgrade_test.go | 11 ++++++++ 8 files changed, 75 insertions(+) create mode 100644 cmd/helm/testdata/testcharts/alpine-app-version/Chart.yaml create mode 100644 cmd/helm/testdata/testcharts/alpine-app-version/README.md create mode 100644 cmd/helm/testdata/testcharts/alpine-app-version/extra_values.yaml create mode 100644 cmd/helm/testdata/testcharts/alpine-app-version/more_values.yaml create mode 100644 cmd/helm/testdata/testcharts/alpine-app-version/templates/alpine-pod.yaml create mode 100644 cmd/helm/testdata/testcharts/alpine-app-version/values.yaml diff --git a/cmd/helm/install_test.go b/cmd/helm/install_test.go index 24a5abe68..a4c0cc33e 100644 --- a/cmd/helm/install_test.go +++ b/cmd/helm/install_test.go @@ -191,6 +191,17 @@ func TestInstall(t *testing.T) { flags: []string{"--name-template", "{{UPPER \"foobar\"}}"}, err: true, }, + { + name: "install with app-version (allow)", + args: []string{"testdata/testcharts/alpine-app-version"}, + flags: []string{"--app-version", "1.0.1"}, + }, + { + name: "install with app-version (not allow)", + args: []string{"testdata/testcharts/alpine"}, + flags: []string{"--app-version", "1.0.1"}, + err: true, + }, } runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command { diff --git a/cmd/helm/testdata/testcharts/alpine-app-version/Chart.yaml b/cmd/helm/testdata/testcharts/alpine-app-version/Chart.yaml new file mode 100644 index 000000000..149455604 --- /dev/null +++ b/cmd/helm/testdata/testcharts/alpine-app-version/Chart.yaml @@ -0,0 +1,7 @@ +description: Deploy a basic Alpine Linux pod +home: https://k8s.io/helm +name: alpine +sources: +- https://github.com/helm/helm +version: 0.1.0 +overrideAppVersion: true diff --git a/cmd/helm/testdata/testcharts/alpine-app-version/README.md b/cmd/helm/testdata/testcharts/alpine-app-version/README.md new file mode 100644 index 000000000..3c32de5db --- /dev/null +++ b/cmd/helm/testdata/testcharts/alpine-app-version/README.md @@ -0,0 +1,13 @@ +#Alpine: A simple Helm chart + +Run a single pod of Alpine Linux. + +This example was generated using the command `helm create alpine`. + +The `templates/` directory contains a very simple pod resource with a +couple of parameters. + +The `values.yaml` file contains the default values for the +`alpine-pod.yaml` template. + +You can install this example using `helm install docs/examples/alpine`. diff --git a/cmd/helm/testdata/testcharts/alpine-app-version/extra_values.yaml b/cmd/helm/testdata/testcharts/alpine-app-version/extra_values.yaml new file mode 100644 index 000000000..468bbacbc --- /dev/null +++ b/cmd/helm/testdata/testcharts/alpine-app-version/extra_values.yaml @@ -0,0 +1,2 @@ +test: + Name: extra-values diff --git a/cmd/helm/testdata/testcharts/alpine-app-version/more_values.yaml b/cmd/helm/testdata/testcharts/alpine-app-version/more_values.yaml new file mode 100644 index 000000000..3d21e1fed --- /dev/null +++ b/cmd/helm/testdata/testcharts/alpine-app-version/more_values.yaml @@ -0,0 +1,2 @@ +test: + Name: more-values diff --git a/cmd/helm/testdata/testcharts/alpine-app-version/templates/alpine-pod.yaml b/cmd/helm/testdata/testcharts/alpine-app-version/templates/alpine-pod.yaml new file mode 100644 index 000000000..b8ae22b6c --- /dev/null +++ b/cmd/helm/testdata/testcharts/alpine-app-version/templates/alpine-pod.yaml @@ -0,0 +1,27 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{.Release.Name}}-{{.Values.Name}}" + labels: + # The "heritage" label is used to track which tool deployed a given chart. + # It is useful for admins who want to see what releases a particular tool + # is responsible for. + app.kubernetes.io/managed-by: {{.Release.Service | quote }} + # The "release" convention makes it easy to tie a release to all of the + # Kubernetes resources that were created as part of that release. + app.kubernetes.io/instance: {{.Release.Name | quote }} + # This makes it easy to audit chart usage. + helm.sh/chart: "{{.Chart.Name}}-{{.Chart.Version}}" + values: {{.Values.test.Name}} + annotations: + "helm.sh/created": {{.Release.Time.Seconds | quote }} +spec: + # This shows how to use a simple value. This will look for a passed-in value + # called restartPolicy. If it is not found, it will use the default value. + # {{default "Never" .restartPolicy}} is a slightly optimized version of the + # more conventional syntax: {{.restartPolicy | default "Never"}} + restartPolicy: {{default "Never" .Values.restartPolicy}} + containers: + - name: waiter + image: "alpine:3.3" + command: ["/bin/sleep","9000"] diff --git a/cmd/helm/testdata/testcharts/alpine-app-version/values.yaml b/cmd/helm/testdata/testcharts/alpine-app-version/values.yaml new file mode 100644 index 000000000..879d760f9 --- /dev/null +++ b/cmd/helm/testdata/testcharts/alpine-app-version/values.yaml @@ -0,0 +1,2 @@ +# The pod name +Name: my-alpine diff --git a/cmd/helm/upgrade_test.go b/cmd/helm/upgrade_test.go index c2b1b4ea6..6c5c96caa 100644 --- a/cmd/helm/upgrade_test.go +++ b/cmd/helm/upgrade_test.go @@ -183,6 +183,17 @@ func TestUpgradeCmd(t *testing.T) { resp: helm.ReleaseMock(&helm.MockReleaseOptions{Name: "bonkers-bunny", Version: 1, Chart: ch3}), err: true, }, + { + name: "upgrade with app-version (allow)", + args: []string{"testdata/testcharts/alpine-app-version"}, + flags: []string{"--app-version", "1.0.1"}, + }, + { + name: "upgrade with app-version (not allow)", + args: []string{"testdata/testcharts/alpine"}, + flags: []string{"--app-version", "1.0.1"}, + err: true, + }, } cmd := func(c *helm.FakeClient, out io.Writer) *cobra.Command {