From 4fe8496dd135812c3be481b5262f234515476812 Mon Sep 17 00:00:00 2001 From: Brian Goff Date: Tue, 18 May 2021 18:24:36 +0000 Subject: [PATCH] Fix TestMapReference needed an ordered mapping In 405d5d63b1cfd47b220f95669377e2d51b460cc2 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. --- internal/expansion/expand_test.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/internal/expansion/expand_test.go b/internal/expansion/expand_test.go index 6326994f1..ee6bfbb8f 100644 --- a/internal/expansion/expand_test.go +++ b/internal/expansion/expand_test.go @@ -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{