summaryrefslogtreecommitdiff
path: root/pkg/specgen/generate/kube/play_test.go
diff options
context:
space:
mode:
authorAlban Bedel <albeu@free.fr>2021-03-27 20:27:58 +0100
committerAlban Bedel <albeu@free.fr>2021-03-28 15:01:24 +0200
commit9f92b8b0d8ac34c02100579a5acf6c127392aff5 (patch)
treeaadab9f26b3c714c88e3d6a7aa094066dafeb2af /pkg/specgen/generate/kube/play_test.go
parentec47312eebf11abcf74b5bf06df19ee2fb7b8afd (diff)
downloadpodman-9f92b8b0d8ac34c02100579a5acf6c127392aff5.tar.gz
podman-9f92b8b0d8ac34c02100579a5acf6c127392aff5.tar.bz2
podman-9f92b8b0d8ac34c02100579a5acf6c127392aff5.zip
play kube: prepare supporting other env source than config maps
Rework envVarsFromConfigMap() and envVarValue() to simplify supporting other env sources than config maps. For this we pass the whole spec generator options struct as parameter instead of just the config maps list. Then we rename envVarsFromConfigMap() to envVarsFrom() and in envVarValue() we reposition the loop over the config maps to only run it when a configMapRef element exists. Signed-off-by: Alban Bedel <albeu@free.fr>
Diffstat (limited to 'pkg/specgen/generate/kube/play_test.go')
-rw-r--r--pkg/specgen/generate/kube/play_test.go50
1 files changed, 32 insertions, 18 deletions
diff --git a/pkg/specgen/generate/kube/play_test.go b/pkg/specgen/generate/kube/play_test.go
index 148540e9f..35975a70b 100644
--- a/pkg/specgen/generate/kube/play_test.go
+++ b/pkg/specgen/generate/kube/play_test.go
@@ -8,12 +8,12 @@ import (
v12 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
-func TestEnvVarsFromConfigMap(t *testing.T) {
+func TestEnvVarsFrom(t *testing.T) {
tests := []struct {
- name string
- envFrom v1.EnvFromSource
- configMapList []v1.ConfigMap
- expected map[string]string
+ name string
+ envFrom v1.EnvFromSource
+ options CtrSpecGenOptions
+ expected map[string]string
}{
{
"ConfigMapExists",
@@ -24,7 +24,9 @@ func TestEnvVarsFromConfigMap(t *testing.T) {
},
},
},
- configMapList,
+ CtrSpecGenOptions{
+ ConfigMaps: configMapList,
+ },
map[string]string{
"myvar": "foo",
},
@@ -38,7 +40,9 @@ func TestEnvVarsFromConfigMap(t *testing.T) {
},
},
},
- configMapList,
+ CtrSpecGenOptions{
+ ConfigMaps: configMapList,
+ },
map[string]string{},
},
{
@@ -50,7 +54,9 @@ func TestEnvVarsFromConfigMap(t *testing.T) {
},
},
},
- []v1.ConfigMap{},
+ CtrSpecGenOptions{
+ ConfigMaps: []v1.ConfigMap{},
+ },
map[string]string{},
},
}
@@ -58,7 +64,7 @@ func TestEnvVarsFromConfigMap(t *testing.T) {
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
- result := envVarsFromConfigMap(test.envFrom, test.configMapList)
+ result := envVarsFrom(test.envFrom, &test.options)
assert.Equal(t, test.expected, result)
})
}
@@ -66,10 +72,10 @@ func TestEnvVarsFromConfigMap(t *testing.T) {
func TestEnvVarValue(t *testing.T) {
tests := []struct {
- name string
- envVar v1.EnvVar
- configMapList []v1.ConfigMap
- expected string
+ name string
+ envVar v1.EnvVar
+ options CtrSpecGenOptions
+ expected string
}{
{
"ConfigMapExists",
@@ -84,7 +90,9 @@ func TestEnvVarValue(t *testing.T) {
},
},
},
- configMapList,
+ CtrSpecGenOptions{
+ ConfigMaps: configMapList,
+ },
"foo",
},
{
@@ -100,7 +108,9 @@ func TestEnvVarValue(t *testing.T) {
},
},
},
- configMapList,
+ CtrSpecGenOptions{
+ ConfigMaps: configMapList,
+ },
"",
},
{
@@ -116,7 +126,9 @@ func TestEnvVarValue(t *testing.T) {
},
},
},
- configMapList,
+ CtrSpecGenOptions{
+ ConfigMaps: configMapList,
+ },
"",
},
{
@@ -132,7 +144,9 @@ func TestEnvVarValue(t *testing.T) {
},
},
},
- []v1.ConfigMap{},
+ CtrSpecGenOptions{
+ ConfigMaps: []v1.ConfigMap{},
+ },
"",
},
}
@@ -140,7 +154,7 @@ func TestEnvVarValue(t *testing.T) {
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
- result := envVarValue(test.envVar, test.configMapList)
+ result := envVarValue(test.envVar, &test.options)
assert.Equal(t, test.expected, result)
})
}