Fix TestMapReference needed an ordered mapping

In 405d5d63b1 we changed for an ordered
list to a map, however the test is order dependent go maps are
randomized.

Change the test to use a slice with an internal type (instead of pulling
back in k8s.io/kubernetes).

Without this change this test will fail occasionally and has no
guarentee for success because of the random order of maps.
This commit is contained in:
Brian Goff
2021-05-18 18:24:36 +00:00
parent 5cd25230c5
commit 4fe8496dd1

View File

@@ -5,10 +5,17 @@ import (
)
func TestMapReference(t *testing.T) {
envs := map[string]string{
"FOO": "bar",
"ZOO": "$(FOO)-1",
"BLU": "$(ZOO)-2",
// We use a struct here instead of a map because we need mappings to happen in order.
// Go maps are randomized.
type envVar struct {
Name string
Value string
}
envs := []envVar{
{"FOO", "bar"},
{"ZOO", "$(FOO)-1"},
{"BLU", "$(ZOO)-2"},
}
declaredEnv := map[string]string{
@@ -21,8 +28,8 @@ func TestMapReference(t *testing.T) {
mapping := MappingFuncFor(declaredEnv, serviceEnv)
for k, v := range envs {
declaredEnv[k] = Expand(v, mapping)
for _, env := range envs {
declaredEnv[env.Name] = Expand(env.Value, mapping)
}
expectedEnv := map[string]string{