| 1 |
// Copyright 2019 The Kubernetes Authors. |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package types_test |
| 5 |
|
| 6 |
import ( |
| 7 |
"testing" |
| 8 |
|
| 9 |
"github.com/stretchr/testify/require" |
| 10 |
"sigs.k8s.io/kustomize/api/types" |
| 11 |
) |
| 12 |
|
| 13 |
func TestAsHelmArgs(t *testing.T) { |
| 14 |
t.Run("use generate-name", func(t *testing.T) { |
| 15 |
p := types.HelmChart{ |
| 16 |
Name: "chart-name", |
| 17 |
Version: "1.0.0", |
| 18 |
Repo: "https://helm.releases.hashicorp.com", |
| 19 |
ApiVersions: []string{"foo", "bar"}, |
| 20 |
KubeVersion: "1.27", |
| 21 |
NameTemplate: "template", |
| 22 |
SkipTests: true, |
| 23 |
IncludeCRDs: true, |
| 24 |
SkipHooks: true, |
| 25 |
ValuesFile: "values", |
| 26 |
AdditionalValuesFiles: []string{"values1", "values2"}, |
| 27 |
Namespace: "my-ns", |
| 28 |
} |
| 29 |
require.Equal(t, p.AsHelmArgs("/home/charts"), |
| 30 |
[]string{"template", "--generate-name", |
| 31 |
"/home/charts/chart-name", |
| 32 |
"--namespace", "my-ns", |
| 33 |
"--name-template", "template", |
| 34 |
"-f", "values", |
| 35 |
"-f", "values1", "-f", "values2", |
| 36 |
"--api-versions", "foo", "--api-versions", "bar", |
| 37 |
"--kube-version", "1.27", |
| 38 |
"--include-crds", |
| 39 |
"--skip-tests", |
| 40 |
"--no-hooks"}) |
| 41 |
}) |
| 42 |
|
| 43 |
t.Run("use release-name", func(t *testing.T) { |
| 44 |
p := types.HelmChart{ |
| 45 |
Name: "chart-name", |
| 46 |
Version: "1.0.0", |
| 47 |
Repo: "https://helm.releases.hashicorp.com", |
| 48 |
ApiVersions: []string{"foo", "bar"}, |
| 49 |
NameTemplate: "template", |
| 50 |
ValuesFile: "values", |
| 51 |
AdditionalValuesFiles: []string{"values1", "values2"}, |
| 52 |
Namespace: "my-ns", |
| 53 |
ReleaseName: "test", |
| 54 |
} |
| 55 |
require.Equal(t, p.AsHelmArgs("/home/charts"), |
| 56 |
[]string{"template", "test", "/home/charts/chart-name", |
| 57 |
"--namespace", "my-ns", |
| 58 |
"--name-template", "template", |
| 59 |
"-f", "values", |
| 60 |
"-f", "values1", "-f", "values2", |
| 61 |
"--api-versions", "foo", "--api-versions", "bar"}) |
| 62 |
}) |
| 63 |
|
| 64 |
t.Run("use helm-debug", func(t *testing.T) { |
| 65 |
p := types.HelmChart{ |
| 66 |
Name: "chart-name", |
| 67 |
Version: "1.0.0", |
| 68 |
Repo: "https://helm.releases.hashicorp.com", |
| 69 |
ValuesFile: "values", |
| 70 |
AdditionalValuesFiles: []string{"values1", "values2"}, |
| 71 |
Debug: true, |
| 72 |
} |
| 73 |
require.Equal(t, p.AsHelmArgs("/home/charts"), |
| 74 |
[]string{"template", "--generate-name", "/home/charts/chart-name", |
| 75 |
"-f", "values", |
| 76 |
"-f", "values1", |
| 77 |
"-f", "values2", |
| 78 |
"--debug"}) |
| 79 |
}) |
| 80 |
|
| 81 |
t.Run("use helm-devel", func(t *testing.T) { |
| 82 |
// We first test that the devel flag is only appended when specified |
| 83 |
p := types.HelmChart{ |
| 84 |
Name: "chart-name", |
| 85 |
Version: "1.0.0", |
| 86 |
Repo: "https://helm.releases.hashicorp.com", |
| 87 |
ValuesFile: "values", |
| 88 |
AdditionalValuesFiles: []string{"values1", "values2"}, |
| 89 |
} |
| 90 |
require.Equal(t, p.AsHelmArgs("/home/charts"), |
| 91 |
[]string{"template", "--generate-name", "/home/charts/chart-name", |
| 92 |
"-f", "values", |
| 93 |
"-f", "values1", |
| 94 |
"-f", "values2"}) |
| 95 |
|
| 96 |
p.Devel = true |
| 97 |
require.Equal(t, p.AsHelmArgs("/home/charts"), |
| 98 |
[]string{"template", "--generate-name", "/home/charts/chart-name", |
| 99 |
"-f", "values", |
| 100 |
"-f", "values1", |
| 101 |
"-f", "values2", |
| 102 |
"--devel"}) |
| 103 |
}) |
| 104 |
} |