Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/pages/developing-in-workspaces/devcontainer-json.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ field of the `devcontainer.json` file as follows:
"customizations": {
"devsy": {
"featureDownloadHTTPHeaders": {
"FOO_HEADER": "${env:FOO_ENV_VAR}"
"FOO_HEADER": "${localEnv:FOO_ENV_VAR}"
"BAR_HEADER": "bar"
}
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/devcontainer/config/substitute.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ func replaceWithContext(
return substitutionCtx.DevContainerID
}
return match
case "env":
fallthrough
case "localEnv":
return lookupValue(isWindows, substitutionCtx.Env, args, match)
case "localWorkspaceFolder":
Expand Down
48 changes: 48 additions & 0 deletions pkg/devcontainer/config/substitute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,54 @@ func TestReplaceWithContainerEnvUnknownPreservedAsLiteral(t *testing.T) {
}
}

func TestReplaceWithContextLocalEnvResolves(t *testing.T) {
ctx := &SubstitutionContext{
Env: map[string]string{"HOME": "/root"},
}
match := "${localEnv:HOME}"
result := replaceWithContext(
false, ctx, match, "localEnv", []string{"HOME"},
)
if result != "/root" {
t.Errorf(
"expected localEnv to resolve to %q, got %q",
"/root", result,
)
}
}

func TestReplaceWithContextEnvPreservedAsLiteral(t *testing.T) {
ctx := &SubstitutionContext{
Env: map[string]string{"HOME": "/root"},
}
match := "${env:HOME}"
result := replaceWithContext(
false, ctx, match, "env", []string{"HOME"},
)
if result != match {
t.Errorf(
"expected env var preserved as %q, got %q",
match, result,
)
}
}

func TestReplaceWithContextEnvDefaultPreservedAsLiteral(t *testing.T) {
ctx := &SubstitutionContext{
Env: map[string]string{},
}
match := "${env:MISSING:default}"
result := replaceWithContext(
false, ctx, match, "env", []string{"MISSING", "default"},
)
if result != match {
t.Errorf(
"expected env with default preserved as %q, got %q",
match, result,
)
}
}

func TestResolveStringDefaultWithColons(t *testing.T) {
replace := func(_, variable string, args []string) string {
env := map[string]string{}
Expand Down
Loading