Skip to content

Commit ae63e59

Browse files
committed
fix: support separator char in envvar default value
1 parent 6a1c487 commit ae63e59

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package config
2+
3+
import (
4+
"testing"
5+
"fmt"
6+
)
7+
8+
func TestLookupValue(t *testing.T) {
9+
tests := []struct {
10+
args []string
11+
match string
12+
want string
13+
}{
14+
{args: []string{}, match: "", want: ""},
15+
{args: []string{"foz"}, match: "${env.foz}", want: ""},
16+
{args: []string{"foo","biz"}, match: "${env.foo:biz}", want: "bar"},
17+
{args: []string{"baz","bar"}, match: "${env.baz:bar}", want: "bar"},
18+
{args: []string{"baz","biz","buz"}, match: "${env.baz:biz:buz}", want: "biz:buz"},
19+
}
20+
21+
localVar := map[string]string{
22+
"foo": "bar",
23+
}
24+
25+
for i, tt := range tests {
26+
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) {
27+
if got := lookupValue(false, localVar, tt.args, tt.match); got != tt.want {
28+
t.Errorf("lookupValue(%v, %v, %v, %v) = %v, want %v", false, localVar, tt.args, tt.match, got, tt.want)
29+
}
30+
})
31+
}
32+
}

pkg/devcontainer/config/substitute.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func lookupValue(isWindows bool, env map[string]string, args []string, match str
141141
}
142142

143143
if len(args) > 1 {
144-
defaultValue := args[1]
144+
defaultValue := strings.Join(args[1:], ":")
145145
return defaultValue
146146
}
147147

0 commit comments

Comments
 (0)