From 1afe943983ef259bc1138a312771d49b337cc6c1 Mon Sep 17 00:00:00 2001 From: max06 Date: Tue, 5 Sep 2023 20:53:51 +0000 Subject: [PATCH] Add additional tests --- .../.devcontainer/devcontainer.json | 3 +- .../test-feature/devcontainer-feature.json | 2 +- .../container-features/lifecycleHooks.test.ts | 29 +++++++++++++++---- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/test/container-features/configs/image-with-local-feature/.devcontainer/devcontainer.json b/src/test/container-features/configs/image-with-local-feature/.devcontainer/devcontainer.json index 0749ce284..dd5428211 100644 --- a/src/test/container-features/configs/image-with-local-feature/.devcontainer/devcontainer.json +++ b/src/test/container-features/configs/image-with-local-feature/.devcontainer/devcontainer.json @@ -4,5 +4,6 @@ "features": { "./test-feature": {} }, - "remoteUser": "vscode" + "remoteUser": "vscode", + "postCreateCommand": "echo ${remoteUser} > /tmp/container.variable-substitution.testMarker" } \ No newline at end of file diff --git a/src/test/container-features/configs/image-with-local-feature/.devcontainer/test-feature/devcontainer-feature.json b/src/test/container-features/configs/image-with-local-feature/.devcontainer/test-feature/devcontainer-feature.json index 3a8b63cfd..32ef54c9d 100644 --- a/src/test/container-features/configs/image-with-local-feature/.devcontainer/test-feature/devcontainer-feature.json +++ b/src/test/container-features/configs/image-with-local-feature/.devcontainer/test-feature/devcontainer-feature.json @@ -11,5 +11,5 @@ "type": "volume" } ], - "postCreateCommand": "/usr/bin/whoami && echo ${remoteUser} > /tmp/variable-substitution.testMarker" + "postCreateCommand": "/usr/bin/whoami && echo ${remoteUser} > /tmp/feature.variable-substitution.testMarker" } \ No newline at end of file diff --git a/src/test/container-features/lifecycleHooks.test.ts b/src/test/container-features/lifecycleHooks.test.ts index af3de8664..ade8310b2 100644 --- a/src/test/container-features/lifecycleHooks.test.ts +++ b/src/test/container-features/lifecycleHooks.test.ts @@ -390,15 +390,34 @@ describe('Feature lifecycle hooks', function () { }); it('executes lifecycle hooks with variable substitution', async () => { - const res = await shellExec(`${cli} exec --workspace-folder ${testFolder} cat /tmp/variable-substitution.testMarker`); - assert.strictEqual(res.error, null); + const res1 = await shellExec(`${cli} exec --workspace-folder ${testFolder} cat /tmp/feature.variable-substitution.testMarker`); + assert.strictEqual(res1.error, null); - const outputOfExecCommand = res.stdout; - console.log(outputOfExecCommand); + const outputOfExecCommand1 = res1.stdout; + console.log(outputOfExecCommand1); // Executes the command that was installed by the local Feature's 'postCreateCommand'. - assert.match(outputOfExecCommand, /vscode/); + assert.strictEqual(outputOfExecCommand1, 'vscode\n'); assert.match(containerUpStandardError, /Running the postCreateCommand from Feature '.\/test-feature/); + + // substitutuin in main devcontainer.json + const res2 = await shellExec(`${cli} exec --workspace-folder ${testFolder} cat /tmp/container.variable-substitution.testMarker`); + assert.strictEqual(res2.error, null); + + const outputOfExecCommand2 = res2.stdout; + console.log(outputOfExecCommand2); + + // Executes the command that was installed by the local Feature's 'postCreateCommand'. + assert.strictEqual(outputOfExecCommand2, 'vscode\n'); + assert.match(containerUpStandardError, /Running the postCreateCommand from devcontainer.json/); + + // Check if substituted mount path is in use + const res3 = await shellExec(`docker inspect ${containerId} --format '{{json .Mounts}}'`); + assert.strictEqual(res3.error, null); + + // json parse res3 + const mounts = JSON.parse(res3.stdout); + assert.exists(mounts.find((item: { Type: string; Destination: string }) => item.Type === 'volume' && item.Destination === '/home/vscode')); }); }); });