Skip to content

Commit 1afe943

Browse files
committed
Add additional tests
1 parent cf32d27 commit 1afe943

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"features": {
55
"./test-feature": {}
66
},
7-
"remoteUser": "vscode"
7+
"remoteUser": "vscode",
8+
"postCreateCommand": "echo ${remoteUser} > /tmp/container.variable-substitution.testMarker"
89
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
"type": "volume"
1212
}
1313
],
14-
"postCreateCommand": "/usr/bin/whoami && echo ${remoteUser} > /tmp/variable-substitution.testMarker"
14+
"postCreateCommand": "/usr/bin/whoami && echo ${remoteUser} > /tmp/feature.variable-substitution.testMarker"
1515
}

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

+24-5
Original file line numberDiff line numberDiff line change
@@ -390,15 +390,34 @@ describe('Feature lifecycle hooks', function () {
390390
});
391391

392392
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);
393+
const res1 = await shellExec(`${cli} exec --workspace-folder ${testFolder} cat /tmp/feature.variable-substitution.testMarker`);
394+
assert.strictEqual(res1.error, null);
395395

396-
const outputOfExecCommand = res.stdout;
397-
console.log(outputOfExecCommand);
396+
const outputOfExecCommand1 = res1.stdout;
397+
console.log(outputOfExecCommand1);
398398

399399
// Executes the command that was installed by the local Feature's 'postCreateCommand'.
400-
assert.match(outputOfExecCommand, /vscode/);
400+
assert.strictEqual(outputOfExecCommand1, 'vscode\n');
401401
assert.match(containerUpStandardError, /Running the postCreateCommand from Feature '.\/test-feature/);
402+
403+
// substitutuin in main devcontainer.json
404+
const res2 = await shellExec(`${cli} exec --workspace-folder ${testFolder} cat /tmp/container.variable-substitution.testMarker`);
405+
assert.strictEqual(res2.error, null);
406+
407+
const outputOfExecCommand2 = res2.stdout;
408+
console.log(outputOfExecCommand2);
409+
410+
// Executes the command that was installed by the local Feature's 'postCreateCommand'.
411+
assert.strictEqual(outputOfExecCommand2, 'vscode\n');
412+
assert.match(containerUpStandardError, /Running the postCreateCommand from devcontainer.json/);
413+
414+
// Check if substituted mount path is in use
415+
const res3 = await shellExec(`docker inspect ${containerId} --format '{{json .Mounts}}'`);
416+
assert.strictEqual(res3.error, null);
417+
418+
// json parse res3
419+
const mounts = JSON.parse(res3.stdout);
420+
assert.exists(mounts.find((item: { Type: string; Destination: string }) => item.Type === 'volume' && item.Destination === '/home/vscode'));
402421
});
403422
});
404423
});

0 commit comments

Comments
 (0)