diff --git a/pkg/devcontainer/config/substiture_test.go b/pkg/devcontainer/config/substiture_test.go new file mode 100644 index 000000000..fe026b9bd --- /dev/null +++ b/pkg/devcontainer/config/substiture_test.go @@ -0,0 +1,32 @@ +package config + +import ( + "testing" + "fmt" +) + +func TestLookupValue(t *testing.T) { + tests := []struct { + args []string + match string + want string + }{ + {args: []string{}, match: "", want: ""}, + {args: []string{"foz"}, match: "${env.foz}", want: ""}, + {args: []string{"foo","biz"}, match: "${env.foo:biz}", want: "bar"}, + {args: []string{"baz","bar"}, match: "${env.baz:bar}", want: "bar"}, + {args: []string{"baz","biz","buz"}, match: "${env.baz:biz:buz}", want: "biz:buz"}, + } + + localVar := map[string]string{ + "foo": "bar", + } + + for i, tt := range tests { + t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { + if got := lookupValue(false, localVar, tt.args, tt.match); got != tt.want { + t.Errorf("lookupValue(%v, %v, %v, %v) = %v, want %v", false, localVar, tt.args, tt.match, got, tt.want) + } + }) + } +} diff --git a/pkg/devcontainer/config/substitute.go b/pkg/devcontainer/config/substitute.go index 22945d170..600c44c27 100644 --- a/pkg/devcontainer/config/substitute.go +++ b/pkg/devcontainer/config/substitute.go @@ -141,7 +141,7 @@ func lookupValue(isWindows bool, env map[string]string, args []string, match str } if len(args) > 1 { - defaultValue := args[1] + defaultValue := strings.Join(args[1:], ":") return defaultValue }