(t *testing.T)
| 1143 | } |
| 1144 | |
| 1145 | func TestContainerEnv(t *testing.T) { |
| 1146 | t.Parallel() |
| 1147 | |
| 1148 | // Ensures that a Git repository with a devcontainer.json is cloned and built. |
| 1149 | srv := gittest.CreateGitServer(t, gittest.Options{ |
| 1150 | Files: map[string]string{ |
| 1151 | ".devcontainer/devcontainer.json": `{ |
| 1152 | "name": "Test", |
| 1153 | "build": { |
| 1154 | "dockerfile": "Dockerfile" |
| 1155 | }, |
| 1156 | "containerEnv": { |
| 1157 | "FROM_CONTAINER_ENV": "bar", |
| 1158 | "PATH": "/bin" |
| 1159 | }, |
| 1160 | "remoteEnv": { |
| 1161 | "FROM_REMOTE_ENV": "baz", |
| 1162 | "PATH": "/usr/local/bin:${containerEnv:PATH}:${containerEnv:GOPATH:/go/bin}:/opt", |
| 1163 | "REMOTE_BAR": "${FROM_CONTAINER_ENV}" |
| 1164 | } |
| 1165 | }`, |
| 1166 | ".devcontainer/Dockerfile": "FROM " + testImageAlpine + "\nENV FROM_DOCKERFILE=foo", |
| 1167 | }, |
| 1168 | }) |
| 1169 | ctr, err := runEnvbuilder(t, runOpts{env: []string{ |
| 1170 | envbuilderEnv("GIT_URL", srv.URL), |
| 1171 | envbuilderEnv("EXPORT_ENV_FILE", "/env"), |
| 1172 | }}) |
| 1173 | require.NoError(t, err) |
| 1174 | |
| 1175 | output := execContainer(t, ctr, "cat /env") |
| 1176 | want := `DEVCONTAINER=true |
| 1177 | DEVCONTAINER_CONFIG=/workspaces/empty/.devcontainer/devcontainer.json |
| 1178 | ENVBUILDER=true |
| 1179 | FROM_CONTAINER_ENV=bar |
| 1180 | FROM_DOCKERFILE=foo |
| 1181 | FROM_REMOTE_ENV=baz |
| 1182 | PATH=/usr/local/bin:/bin:/go/bin:/opt |
| 1183 | REMOTE_BAR=bar` |
| 1184 | if diff := cmp.Diff(want, strings.TrimSpace(output)); diff != "" { |
| 1185 | require.Failf(t, "env mismatch", "diff (-want +got):\n%s", diff) |
| 1186 | } |
| 1187 | } |
| 1188 | |
| 1189 | func TestUnsetOptionsEnv(t *testing.T) { |
| 1190 | t.Parallel() |
nothing calls this directly
no test coverage detected