Skip to content

Commit

Permalink
test: Improve test to use lifecycleHooks
Browse files Browse the repository at this point in the history
  • Loading branch information
max06 committed Jul 26, 2023
1 parent bb9ceaf commit a3c58da
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
6 changes: 0 additions & 6 deletions src/test/cli.build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,5 @@ describe('Dev Containers CLI', function () {
const details = JSON.parse((await shellExec(`docker inspect test-subfolder-config`)).stdout)[0] as ImageDetails;
assert.strictEqual(envListToObj(details.Config.Env).SUBFOLDER_CONFIG_IMAGE_ENV, 'true');
});

it('should build with a local feature', async () => {
const res = await shellExec(`${cli} build --workspace-folder ${__dirname}/configs/image-with-local-feature --image-name test-local-feature`)
const response = JSON.parse(res.stdout);
assert.strictEqual(response.outcome, 'success');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
"target": "/home/${remoteUser}",
"type": "volume"
}
]
],
"postCreateCommand": "/usr/bin/whoami && echo ${remoteUser} > /tmp/variable-substitution.testMarker"
}
32 changes: 32 additions & 0 deletions src/test/container-features/lifecycleHooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,38 @@ describe('Feature lifecycle hooks', function () {
});
});

describe('lifecycle-hooks-with-variable-substitution', () => {
describe('devcontainer up', () => {
let containerId: string | null = null;
let containerUpStandardError: string;
const testFolder = `${__dirname}/configs/image-with-local-feature`;

before(async () => {
await shellExec(`rm -f ${testFolder}/*.testMarker`, undefined, undefined, true);
const res = await devContainerUp(cli, testFolder, { 'logLevel': 'trace' });
containerId = res.containerId;
containerUpStandardError = res.stderr;
});

after(async () => {
await devContainerDown({ containerId });
await shellExec(`rm -f ${testFolder}/*.testMarker`, undefined, undefined, true);
});

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 outputOfExecCommand = res.stdout;
console.log(outputOfExecCommand);

// Executes the command that was installed by the local Feature's 'postCreateCommand'.
assert.match(outputOfExecCommand, /vscode/);
assert.match(containerUpStandardError, /Running the postCreateCommand from Feature '.\/test-feature/);
});
});
});

describe('lifecycle-hooks-advanced', () => {

describe(`devcontainer up`, () => {
Expand Down

0 comments on commit a3c58da

Please sign in to comment.