Skip to content

Commit

Permalink
fix: support separator char in envvar default value
Browse files Browse the repository at this point in the history
  • Loading branch information
acolombier committed Jan 18, 2025
1 parent 6a1c487 commit ae63e59
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 32 additions & 0 deletions pkg/devcontainer/config/substiture_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
})
}
}
2 changes: 1 addition & 1 deletion pkg/devcontainer/config/substitute.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit ae63e59

Please sign in to comment.