(t *testing.T)
| 1273 | } |
| 1274 | |
| 1275 | func TestLifecycleScripts(t *testing.T) { |
| 1276 | t.Parallel() |
| 1277 | |
| 1278 | for _, tt := range []struct { |
| 1279 | name string |
| 1280 | files map[string]string |
| 1281 | outputCmd string |
| 1282 | expectOutput string |
| 1283 | }{ |
| 1284 | { |
| 1285 | name: "build", |
| 1286 | files: map[string]string{ |
| 1287 | ".devcontainer/devcontainer.json": `{ |
| 1288 | "name": "Test", |
| 1289 | "build": { |
| 1290 | "dockerfile": "Dockerfile" |
| 1291 | }, |
| 1292 | "onCreateCommand": "echo create > /tmp/out", |
| 1293 | "updateContentCommand": ["sh", "-c", "echo update >> /tmp/out"], |
| 1294 | "postCreateCommand": "(echo -n postCreate. ; id -un) >> /tmp/out", |
| 1295 | "postStartCommand": { |
| 1296 | "parallel1": "echo parallel1 > /tmp/parallel1", |
| 1297 | "parallel2": ["sh", "-c", "echo parallel2 > /tmp/parallel2"] |
| 1298 | } |
| 1299 | }`, |
| 1300 | ".devcontainer/Dockerfile": "FROM " + testImageAlpine + "\nUSER nobody", |
| 1301 | }, |
| 1302 | outputCmd: "cat /tmp/out /tmp/parallel1 /tmp/parallel2", |
| 1303 | expectOutput: "create\nupdate\npostCreate.nobody\nparallel1\nparallel2", |
| 1304 | }, |
| 1305 | { |
| 1306 | name: "image", |
| 1307 | files: map[string]string{ |
| 1308 | ".devcontainer/devcontainer.json": fmt.Sprintf(`{ |
| 1309 | "name": "Test", |
| 1310 | "image": %q, |
| 1311 | "containerUser": "nobody", |
| 1312 | "onCreateCommand": "echo create > /tmp/out", |
| 1313 | "updateContentCommand": ["sh", "-c", "echo update >> /tmp/out"], |
| 1314 | "postCreateCommand": "(echo -n postCreate. ; id -un) >> /tmp/out", |
| 1315 | "postStartCommand": { |
| 1316 | "parallel1": "echo parallel1 > /tmp/parallel1", |
| 1317 | "parallel2": ["sh", "-c", "echo parallel2 > /tmp/parallel2"] |
| 1318 | } |
| 1319 | }`, testImageAlpine), |
| 1320 | }, |
| 1321 | outputCmd: "cat /tmp/out /tmp/parallel1 /tmp/parallel2", |
| 1322 | expectOutput: "create\nupdate\npostCreate.nobody\nparallel1\nparallel2", |
| 1323 | }, |
| 1324 | { |
| 1325 | name: "label", |
| 1326 | files: map[string]string{ |
| 1327 | ".devcontainer/Dockerfile": fmt.Sprintf(`FROM %s |
| 1328 | LABEL devcontainer.metadata='[{ \ |
| 1329 | "onCreateCommand": "echo create > /tmp/out", \ |
| 1330 | "updateContentCommand": ["sh", "-c", "echo update >> /tmp/out"], \ |
| 1331 | "postCreateCommand": "(echo -n postCreate. ; id -un) >> /tmp/out", \ |
| 1332 | "postStartCommand": { \ |
nothing calls this directly
no test coverage detected