(t *testing.T)
| 182 | } |
| 183 | |
| 184 | func TestReadFromYaml_OverrideNamespace(t *testing.T) { |
| 185 | yamlFile := "/example/path/to/helmfile.yaml" |
| 186 | yamlContent := []byte(`environments: |
| 187 | production: |
| 188 | values: |
| 189 | - foo.yaml |
| 190 | - bar.yaml.gotmpl |
| 191 | |
| 192 | # A.k.a helmfile apply --namespace myns |
| 193 | namespace: myns |
| 194 | |
| 195 | releases: |
| 196 | - name: myrelease |
| 197 | namespace: mynamespace |
| 198 | chart: mychart |
| 199 | values: |
| 200 | - values.yaml.gotmpl |
| 201 | `) |
| 202 | |
| 203 | fooYamlFile := "/example/path/to/foo.yaml" |
| 204 | fooYamlContent := []byte(`foo: foo |
| 205 | # As this file doesn't have an file extension ".gotmpl", this template expression should not be evaluated |
| 206 | baz: "{{ readFile \"baz.txt\" }}"`) |
| 207 | |
| 208 | barYamlFile := "/example/path/to/bar.yaml.gotmpl" |
| 209 | barYamlContent := []byte(`foo: FOO |
| 210 | bar: {{ readFile "bar.txt" }} |
| 211 | `) |
| 212 | |
| 213 | barTextFile := "/example/path/to/bar.txt" |
| 214 | barTextContent := []byte("BAR") |
| 215 | |
| 216 | expected := map[string]interface{}{ |
| 217 | "foo": "FOO", |
| 218 | "bar": "BAR", |
| 219 | // As the file doesn't have an file extension ".gotmpl", this template expression should not be evaluated |
| 220 | "baz": "{{ readFile \"baz.txt\" }}", |
| 221 | } |
| 222 | |
| 223 | valuesFile := "/example/path/to/values.yaml.gotmpl" |
| 224 | valuesContent := []byte(`env: {{ .Environment.Name }} |
| 225 | releaseName: {{ .Release.Name }} |
| 226 | releaseNamespace: {{ .Release.Namespace }} |
| 227 | overrideNamespace: {{ .Namespace }} |
| 228 | `) |
| 229 | |
| 230 | expectedValues := `env: production |
| 231 | releaseName: myrelease |
| 232 | releaseNamespace: myns |
| 233 | overrideNamespace: myns |
| 234 | ` |
| 235 | |
| 236 | testFs := testhelper.NewTestFs(map[string]string{ |
| 237 | fooYamlFile: string(fooYamlContent), |
| 238 | barYamlFile: string(barYamlContent), |
| 239 | barTextFile: string(barTextContent), |
| 240 | valuesFile: string(valuesContent), |
| 241 | }) |
nothing calls this directly
no test coverage detected