(t *testing.T)
| 1360 | } |
| 1361 | |
| 1362 | func TestPostStartScript(t *testing.T) { |
| 1363 | t.Parallel() |
| 1364 | |
| 1365 | // Ensures that a Git repository with a devcontainer.json is cloned and built. |
| 1366 | srv := gittest.CreateGitServer(t, gittest.Options{ |
| 1367 | Files: map[string]string{ |
| 1368 | ".devcontainer/devcontainer.json": `{ |
| 1369 | "name": "Test", |
| 1370 | "build": { |
| 1371 | "dockerfile": "Dockerfile" |
| 1372 | }, |
| 1373 | "postStartCommand": { |
| 1374 | "command1": "echo command1 output > /tmp/out1", |
| 1375 | "command2": ["sh", "-c", "echo 'contains \"double quotes\"' > '/tmp/out2'"] |
| 1376 | } |
| 1377 | }`, |
| 1378 | ".devcontainer/init.sh": `#!/bin/sh |
| 1379 | /tmp/post-start.sh |
| 1380 | sleep infinity`, |
| 1381 | ".devcontainer/Dockerfile": `FROM ` + testImageAlpine + ` |
| 1382 | COPY init.sh /bin |
| 1383 | RUN chmod +x /bin/init.sh |
| 1384 | USER nobody`, |
| 1385 | }, |
| 1386 | }) |
| 1387 | ctr, err := runEnvbuilder(t, runOpts{env: []string{ |
| 1388 | envbuilderEnv("GIT_URL", srv.URL), |
| 1389 | envbuilderEnv("POST_START_SCRIPT_PATH", "/tmp/post-start.sh"), |
| 1390 | envbuilderEnv("INIT_COMMAND", "/bin/init.sh"), |
| 1391 | }}) |
| 1392 | require.NoError(t, err) |
| 1393 | |
| 1394 | output := execContainer(t, ctr, "cat /tmp/post-start.sh /tmp/out1 /tmp/out2") |
| 1395 | require.Equal(t, |
| 1396 | `#!/bin/sh |
| 1397 | |
| 1398 | echo command1 output > /tmp/out1 |
| 1399 | 'sh' '-c' 'echo '"'"'contains "double quotes"'"'"' > '"'"'/tmp/out2'"'"'' |
| 1400 | command1 output |
| 1401 | contains "double quotes"`, strings.TrimSpace(output)) |
| 1402 | } |
| 1403 | |
| 1404 | func TestPrivateRegistry(t *testing.T) { |
| 1405 | t.Parallel() |
nothing calls this directly
no test coverage detected