Skip to content

Commit a3c58da

Browse files
committed
test: Improve test to use lifecycleHooks
1 parent bb9ceaf commit a3c58da

File tree

5 files changed

+34
-7
lines changed

5 files changed

+34
-7
lines changed

src/test/cli.build.test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,5 @@ describe('Dev Containers CLI', function () {
260260
const details = JSON.parse((await shellExec(`docker inspect test-subfolder-config`)).stdout)[0] as ImageDetails;
261261
assert.strictEqual(envListToObj(details.Config.Env).SUBFOLDER_CONFIG_IMAGE_ENV, 'true');
262262
});
263-
264-
it('should build with a local feature', async () => {
265-
const res = await shellExec(`${cli} build --workspace-folder ${__dirname}/configs/image-with-local-feature --image-name test-local-feature`)
266-
const response = JSON.parse(res.stdout);
267-
assert.strictEqual(response.outcome, 'success');
268-
});
269263
});
270264
});

src/test/configs/image-with-local-feature/.devcontainer/test-feature/devcontainer-feature.json renamed to src/test/container-features/configs/image-with-local-feature/.devcontainer/test-feature/devcontainer-feature.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
"target": "/home/${remoteUser}",
1111
"type": "volume"
1212
}
13-
]
13+
],
14+
"postCreateCommand": "/usr/bin/whoami && echo ${remoteUser} > /tmp/variable-substitution.testMarker"
1415
}

src/test/container-features/lifecycleHooks.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,38 @@ describe('Feature lifecycle hooks', function () {
371371
});
372372
});
373373

374+
describe('lifecycle-hooks-with-variable-substitution', () => {
375+
describe('devcontainer up', () => {
376+
let containerId: string | null = null;
377+
let containerUpStandardError: string;
378+
const testFolder = `${__dirname}/configs/image-with-local-feature`;
379+
380+
before(async () => {
381+
await shellExec(`rm -f ${testFolder}/*.testMarker`, undefined, undefined, true);
382+
const res = await devContainerUp(cli, testFolder, { 'logLevel': 'trace' });
383+
containerId = res.containerId;
384+
containerUpStandardError = res.stderr;
385+
});
386+
387+
after(async () => {
388+
await devContainerDown({ containerId });
389+
await shellExec(`rm -f ${testFolder}/*.testMarker`, undefined, undefined, true);
390+
});
391+
392+
it('executes lifecycle hooks with variable substitution', async () => {
393+
const res = await shellExec(`${cli} exec --workspace-folder ${testFolder} cat /tmp/variable-substitution.testMarker`);
394+
assert.strictEqual(res.error, null);
395+
396+
const outputOfExecCommand = res.stdout;
397+
console.log(outputOfExecCommand);
398+
399+
// Executes the command that was installed by the local Feature's 'postCreateCommand'.
400+
assert.match(outputOfExecCommand, /vscode/);
401+
assert.match(containerUpStandardError, /Running the postCreateCommand from Feature '.\/test-feature/);
402+
});
403+
});
404+
});
405+
374406
describe('lifecycle-hooks-advanced', () => {
375407

376408
describe(`devcontainer up`, () => {

0 commit comments

Comments
 (0)