github.com/codefresh-io/kcfi@v0.0.0-20230301195427-c1578715cc46/cmd/kcfi/template_test.go (about) 1 /* 2 Copyright The Helm Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package main 18 19 import ( 20 "fmt" 21 "path/filepath" 22 "testing" 23 ) 24 25 var chartPath = "./../../pkg/chartutil/testdata/subpop/charts/subchart1" 26 27 func TestTemplateCmd(t *testing.T) { 28 tests := []cmdTestCase{ 29 { 30 name: "check name", 31 cmd: fmt.Sprintf("template '%s'", chartPath), 32 golden: "output/template.txt", 33 }, 34 { 35 name: "check set name", 36 cmd: fmt.Sprintf("template '%s' --set service.name=apache", chartPath), 37 golden: "output/template-set.txt", 38 }, 39 { 40 name: "check values files", 41 cmd: fmt.Sprintf("template '%s' --values '%s'", chartPath, filepath.Join(chartPath, "/charts/subchartA/values.yaml")), 42 golden: "output/template-values-files.txt", 43 }, 44 { 45 name: "check name template", 46 cmd: fmt.Sprintf(`template '%s' --name-template='foobar-{{ b64enc "abc" }}-baz'`, chartPath), 47 golden: "output/template-name-template.txt", 48 }, 49 { 50 name: "check no args", 51 cmd: "template", 52 wantError: true, 53 golden: "output/template-no-args.txt", 54 }, 55 { 56 name: "check library chart", 57 cmd: fmt.Sprintf("template '%s'", "testdata/testcharts/lib-chart"), 58 wantError: true, 59 golden: "output/template-lib-chart.txt", 60 }, 61 { 62 name: "check chart bad type", 63 cmd: fmt.Sprintf("template '%s'", "testdata/testcharts/chart-bad-type"), 64 wantError: true, 65 golden: "output/install-chart-bad-type.txt", 66 }, 67 { 68 name: "check chart with dependency which is an app chart acting as a library chart", 69 cmd: fmt.Sprintf("template '%s'", "testdata/testcharts/chart-with-template-lib-dep"), 70 golden: "output/template-chart-with-template-lib-dep.txt", 71 }, 72 { 73 name: "check chart with dependency which is an app chart archive acting as a library chart", 74 cmd: fmt.Sprintf("template '%s'", "testdata/testcharts/chart-with-template-lib-archive-dep"), 75 golden: "output/template-chart-with-template-lib-archive-dep.txt", 76 }, 77 { 78 name: "check kube api versions", 79 cmd: fmt.Sprintf("template --api-versions helm.k8s.io/test '%s'", chartPath), 80 golden: "output/template-with-api-version.txt", 81 }, 82 { 83 name: "template with CRDs", 84 cmd: fmt.Sprintf("template '%s' --include-crds", chartPath), 85 golden: "output/template-with-crds.txt", 86 }, 87 { 88 name: "template with show-only one", 89 cmd: fmt.Sprintf("template '%s' --show-only templates/service.yaml", chartPath), 90 golden: "output/template-show-only-one.txt", 91 }, 92 { 93 name: "template with show-only multiple", 94 cmd: fmt.Sprintf("template '%s' --show-only templates/service.yaml --show-only charts/subcharta/templates/service.yaml", chartPath), 95 golden: "output/template-show-only-multiple.txt", 96 }, 97 { 98 name: "template with show-only glob", 99 cmd: fmt.Sprintf("template '%s' --show-only templates/subdir/role*", chartPath), 100 golden: "output/template-show-only-glob.txt", 101 // Repeat to ensure manifest ordering regressions are caught 102 repeat: 10, 103 }, 104 { 105 name: "sorted output of manifests (order of filenames, then order of objects within each YAML file)", 106 cmd: fmt.Sprintf("template '%s'", "testdata/testcharts/object-order"), 107 golden: "output/object-order.txt", 108 // Helm previously used random file order. Repeat the test so we 109 // don't accidentally get the expected result. 110 repeat: 10, 111 }, 112 { 113 name: "chart with template with invalid yaml", 114 cmd: fmt.Sprintf("template '%s'", "testdata/testcharts/chart-with-template-with-invalid-yaml"), 115 wantError: true, 116 golden: "output/template-with-invalid-yaml.txt", 117 }, 118 { 119 name: "chart with template with invalid yaml (--debug)", 120 cmd: fmt.Sprintf("template '%s' --debug", "testdata/testcharts/chart-with-template-with-invalid-yaml"), 121 wantError: true, 122 golden: "output/template-with-invalid-yaml-debug.txt", 123 }, 124 } 125 runTestCmd(t, tests) 126 }