ContainerPatch supports all common workload paths

This commit is contained in:
Katrina Verey
2021-08-10 16:08:28 -07:00
parent 7a41e479c9
commit f0b4cc4581
11 changed files with 232 additions and 2 deletions

View File

@@ -5,6 +5,7 @@ package framework_test
import (
"bytes"
"regexp"
"strings"
"testing"
@@ -276,6 +277,57 @@ functionConfig:
`), strings.TrimSpace(out.String()))
}
func TestTemplateProcessor_ContainerPatchTemplates_MultipleWorkloadKinds(t *testing.T) {
type API struct {
Spec struct {
Key string `json:"key" yaml:"key"`
Value string `json:"value" yaml:"value"`
A string `json:"a" yaml:"a"`
}
}
config := &API{}
p := framework.TemplateProcessor{
TemplateData: config,
ResourceTemplates: []framework.ResourceTemplate{{
Templates: parser.TemplateFiles("testdata/template-processor/templates/container-sources"),
}},
PatchTemplates: []framework.PatchTemplate{
&framework.ContainerPatchTemplate{
Templates: parser.TemplateFiles("testdata/template-processor/container-patches"),
},
},
}
out := new(bytes.Buffer)
rw := &kio.ByteReadWriter{Writer: out, Reader: bytes.NewBufferString(`
apiVersion: config.kubernetes.io/v1alpha1
kind: ResourceList
items: []
functionConfig:
spec:
key: Hello
value: World
a: bar
`)}
require.NoError(t, framework.Execute(p, rw))
resources, err := (&kio.ByteReader{Reader: out}).Read()
require.NoError(t, err)
envRegex := regexp.MustCompile(strings.TrimSpace(`
\s+ env:
\s+ - name: EXISTING
\s+ value: variable
\s+ - name: Hello
\s+ value: World
`))
require.Equal(t, 9, len(resources))
for i, r := range resources {
t.Run(r.GetKind(), func(t *testing.T) {
assert.Regexp(t, envRegex, resources[i].MustString())
})
}
}
func TestSimpleProcessor_Process_loads_config(t *testing.T) {
cfg := new(struct {
Value string `yaml:"value"`