Skip to content

Commit

Permalink
Add additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
max06 committed Sep 5, 2023
1 parent cf32d27 commit 1afe943
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"features": {
"./test-feature": {}
},
"remoteUser": "vscode"
"remoteUser": "vscode",
"postCreateCommand": "echo ${remoteUser} > /tmp/container.variable-substitution.testMarker"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
29 changes: 24 additions & 5 deletions src/test/container-features/lifecycleHooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});
});
});
Expand Down

0 comments on commit 1afe943

Please sign in to comment.