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

Function TestPostStartScript

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

Source from the content-addressed store, hash-verified

1360}
1361
1362func 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 + `
1382COPY init.sh /bin
1383RUN chmod +x /bin/init.sh
1384USER 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
1398echo command1 output > /tmp/out1
1399'sh' '-c' 'echo '"'"'contains "double quotes"'"'"' > '"'"'/tmp/out2'"'"''
1400command1 output
1401contains "double quotes"`, strings.TrimSpace(output))
1402}
1403
1404func TestPrivateRegistry(t *testing.T) {
1405 t.Parallel()

Callers

nothing calls this directly

Calls 4

CreateGitServerFunction · 0.92
runEnvbuilderFunction · 0.85
envbuilderEnvFunction · 0.85
execContainerFunction · 0.85

Tested by

no test coverage detected