MCPcopy Create free account
hub / github.com/coder/envbuilder / TestUnsetOptionsEnv

Function TestUnsetOptionsEnv

integration/integration_test.go:1189–1227  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1187}
1188
1189func TestUnsetOptionsEnv(t *testing.T) {
1190 t.Parallel()
1191
1192 // Ensures that a Git repository with a devcontainer.json is cloned and built.
1193 srv := gittest.CreateGitServer(t, gittest.Options{
1194 Files: map[string]string{
1195 ".devcontainer/devcontainer.json": `{
1196 "name": "Test",
1197 "build": {
1198 "dockerfile": "Dockerfile"
1199 },
1200 }`,
1201 ".devcontainer/Dockerfile": "FROM " + testImageAlpine + "\nENV FROM_DOCKERFILE=foo",
1202 },
1203 })
1204 ctr, err := runEnvbuilder(t, runOpts{env: []string{
1205 envbuilderEnv("GIT_URL", srv.URL),
1206 "GIT_URL", srv.URL,
1207 envbuilderEnv("GIT_PASSWORD", "supersecret"),
1208 "GIT_PASSWORD", "supersecret",
1209 envbuilderEnv("INIT_SCRIPT", "env > /root/env.txt && sleep infinity"),
1210 "INIT_SCRIPT", "env > /root/env.txt && sleep infinity",
1211 }})
1212 require.NoError(t, err)
1213
1214 output := execContainer(t, ctr, "cat /root/env.txt")
1215 var os options.Options
1216 for _, s := range strings.Split(strings.TrimSpace(output), "\n") {
1217 for _, o := range os.CLI() {
1218 if strings.HasPrefix(s, o.Env) {
1219 assert.Fail(t, "environment variable should be stripped when running init script", s)
1220 }
1221 optWithoutPrefix := strings.TrimPrefix(o.Env, options.WithEnvPrefix(""))
1222 if strings.HasPrefix(s, optWithoutPrefix) {
1223 assert.Fail(t, "environment variable should be stripped when running init script", s)
1224 }
1225 }
1226 }
1227}
1228
1229func TestBuildSecrets(t *testing.T) {
1230 t.Parallel()

Callers

nothing calls this directly

Calls 6

CLIMethod · 0.95
CreateGitServerFunction · 0.92
WithEnvPrefixFunction · 0.92
runEnvbuilderFunction · 0.85
envbuilderEnvFunction · 0.85
execContainerFunction · 0.85

Tested by

no test coverage detected