add tests for parser, install and template cmds

Signed-off-by: Vlad Fratila <vfratila@adobe.com>
Signed-off-by: Matheus Hunsche <matheus.hunsche@ifood.com.br>
pull/8840/head
Vlad Fratila 5 years ago committed by Matheus Hunsche
parent 1dbbc28c75
commit 9e69e66f98

@ -47,6 +47,12 @@ func TestInstall(t *testing.T) {
cmd: "install virgil testdata/testcharts/alpine -f testdata/testcharts/alpine/extra_values.yaml",
golden: "output/install-with-values-file.txt",
},
// Install, external files
{
name: "install with external files",
cmd: "install virgil testdata/testcharts/configmap --include-file external.txt=testdata/external.txt",
golden: "output/install-with-external-files.txt",
},
// Install, no hooks
{
name: "install without hooks",

@ -121,6 +121,11 @@ func TestTemplateCmd(t *testing.T) {
wantError: true,
golden: "output/template-with-invalid-yaml-debug.txt",
},
{
name: "chart with template with external file",
cmd: fmt.Sprintf("template '%s' --include-file external.txt=testdata/external.txt", "testdata/testcharts/configmap"),
golden: "output/template-with-external-file.txt",
},
}
runTestCmd(t, tests)
}

@ -0,0 +1 @@
out-of-chart-dir

@ -0,0 +1,6 @@
NAME: virgil
LAST DEPLOYED: Fri Sep 2 22:04:05 1977
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None

@ -0,0 +1,20 @@
---
# Source: configmap/templates/config-map.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: "RELEASE-NAME-"
labels:
# The "app.kubernetes.io/managed-by" 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: "Helm"
# The "app.kubernetes.io/instance" 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"
app.kubernetes.io/version: 1.0
# This makes it easy to audit chart usage.
helm.sh/chart: "configmap-0.1.0"
data:
external.txt: out-of-chart-dir

@ -0,0 +1,8 @@
apiVersion: v1
appVersion: "1.0"
description: Deploy a basic Config Map from an external file
home: https://helm.sh/helm
name: configmap
sources:
- https://github.com/helm/helm
version: 0.1.0

@ -0,0 +1,18 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: "{{.Release.Name}}-{{.Values.Name}}"
labels:
# The "app.kubernetes.io/managed-by" 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 "app.kubernetes.io/instance" 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 }}
app.kubernetes.io/version: {{ .Chart.AppVersion }}
# This makes it easy to audit chart usage.
helm.sh/chart: "{{.Chart.Name}}-{{.Chart.Version}}"
data:
{{ (.Files.Glob .Values.external).AsConfig | indent 2 }}

@ -0,0 +1 @@
external: external.txt

@ -0,0 +1,41 @@
package files
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestParseIntoString(t *testing.T) {
need := require.New(t)
is := assert.New(t)
dest := make(map[string]string)
goodFlag := "foo.txt=../foo.txt"
anotherFlag := " bar.txt=~/bar.txt, baz.txt=/path/to/baz.txt"
err := ParseIntoString(goodFlag, dest)
need.NoError(err)
err = ParseIntoString(anotherFlag, dest)
need.NoError(err)
is.Contains(dest, "foo.txt")
is.Contains(dest, "bar.txt")
is.Contains(dest, "baz.txt")
is.Equal(dest["foo.txt"], "../foo.txt", "foo.txt not mapped properly")
is.Equal(dest["bar.txt"], "~/bar.txt", "bar.txt not mapped properly")
is.Equal(dest["baz.txt"], "/path/to/baz.txt", "baz.txt not mapped properly")
overwriteFlag := "foo.txt=../new_foo.txt"
err = ParseIntoString(overwriteFlag, dest)
need.NoError(err)
is.Equal(dest["foo.txt"], "../new_foo.txt")
badFlag := "empty.txt"
err = ParseIntoString(badFlag, dest)
is.NotNil(err)
}
Loading…
Cancel
Save