Skip to content

Commit

Permalink
Update tests (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmarti committed Mar 10, 2023
1 parent e4a7b11 commit 488e6b1
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 106 deletions.
100 changes: 48 additions & 52 deletions src/test/cli.exec.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ export function describeTests1({ text, options }: BuildKitOption) {
afterEach(async () => await devContainerDown({ containerId }));
it('should execute successfully', async () => {
const res = await shellExec(`${cli} exec --workspace-folder ${testFolder} echo hi`);
const response = JSON.parse(res.stdout);
assert.equal(response.outcome, 'success');
assert.strictEqual(res.error, null);
});
});
describe(`with valid (image) config containing features [${text}]`, () => {
Expand All @@ -43,17 +42,17 @@ export function describeTests1({ text, options }: BuildKitOption) {
afterEach(async () => await devContainerDown({ containerId }));
it('should have access to installed features (docker)', async () => {
const res = await shellExec(`${cli} exec --workspace-folder ${testFolder} docker --version`);
const response = JSON.parse(res.stdout);
console.log(res.stdout);
console.log(res.stderr);
assert.equal(response.outcome, 'success');
assert.match(res.stderr, /Docker version/);
assert.strictEqual(res.error, null);
assert.match(res.stdout, /Docker version/);
});
it('should have access to installed features (hello)', async () => {
const res = await shellExec(`${cli} exec --workspace-folder ${testFolder} hello`);
const response = JSON.parse(res.stdout);
console.log(res.stdout);
console.log(res.stderr);
assert.equal(response.outcome, 'success');
assert.match(res.stderr, /howdy, node/);
assert.strictEqual(res.error, null);
assert.match(res.stdout, /howdy, node/);
});
});
describe(`with valid (Dockerfile) config containing features [${text}]`, () => {
Expand All @@ -64,17 +63,17 @@ export function describeTests1({ text, options }: BuildKitOption) {
it('should have access to installed features (docker)', async () => {
// NOTE: Doing a docker ps will ensure that the --privileged flag was set by the feature
const res = await shellExec(`${cli} exec --workspace-folder ${testFolder} docker ps`);
const response = JSON.parse(res.stdout);
console.log(res.stdout);
console.log(res.stderr);
assert.equal(response.outcome, 'success');
assert.match(res.stderr, /CONTAINER ID/);
assert.strictEqual(res.error, null);
assert.match(res.stdout, /CONTAINER ID/);
});
it('should have access to installed features (hello)', async () => {
const res = await shellExec(`${cli} exec --workspace-folder ${testFolder} hello`);
const response = JSON.parse(res.stdout);
console.log(res.stdout);
console.log(res.stderr);
assert.equal(response.outcome, 'success');
assert.match(res.stderr, /howdy, node/);
assert.strictEqual(res.error, null);
assert.match(res.stdout, /howdy, node/);
});
});

Expand All @@ -85,17 +84,17 @@ export function describeTests1({ text, options }: BuildKitOption) {
afterEach(async () => await devContainerDown({ containerId }));
it('should have build marker content', async () => {
const res = await shellExec(`${cli} exec --workspace-folder ${testFolder} cat /var/test-marker`);
const response = JSON.parse(res.stdout);
console.log(res.stdout);
console.log(res.stderr);
assert.equal(response.outcome, 'success');
assert.match(res.stderr, /||test-content||/);
assert.strictEqual(res.error, null);
assert.match(res.stdout, /||test-content||/);
});
it('should have access to installed features (hello)', async () => {
const res = await shellExec(`${cli} exec --workspace-folder ${testFolder} hello`);
const response = JSON.parse(res.stdout);
console.log(res.stdout);
console.log(res.stderr);
assert.equal(response.outcome, 'success');
assert.match(res.stderr, /howdy, node/);
assert.strictEqual(res.error, null);
assert.match(res.stdout, /howdy, node/);
});
});

Expand All @@ -107,17 +106,17 @@ export function describeTests1({ text, options }: BuildKitOption) {
it('should have access to installed features (docker)', async () => {
// NOTE: Doing a docker ps will ensure that the --privileged flag was set by the feature
const res = await shellExec(`${cli} exec --workspace-folder ${testFolder} docker ps`);
const response = JSON.parse(res.stdout);
console.log(res.stdout);
console.log(res.stderr);
assert.equal(response.outcome, 'success');
assert.match(res.stderr, /CONTAINER ID/);
assert.strictEqual(res.error, null);
assert.match(res.stdout, /CONTAINER ID/);
});
it('should have access to installed features (hello)', async () => {
const res = await shellExec(`${cli} exec --workspace-folder ${testFolder} hello`);
const response = JSON.parse(res.stdout);
console.log(res.stdout);
console.log(res.stderr);
assert.equal(response.outcome, 'success');
assert.match(res.stderr, /howdy, node/);
assert.strictEqual(res.error, null);
assert.match(res.stdout, /howdy, node/);
});
});

Expand All @@ -128,17 +127,17 @@ export function describeTests1({ text, options }: BuildKitOption) {
afterEach(async () => await devContainerDown({ composeProjectName }));
it('should have access to installed features (docker)', async () => {
const res = await shellExec(`${cli} exec --workspace-folder ${testFolder} docker --version`);
const response = JSON.parse(res.stdout);
console.log(res.stdout);
console.log(res.stderr);
assert.equal(response.outcome, 'success');
assert.match(res.stderr, /Docker version/);
assert.strictEqual(res.error, null);
assert.match(res.stdout, /Docker version/);
});
it('should have access to installed features (hello)', async () => {
const res = await shellExec(`${cli} exec --workspace-folder ${testFolder} hello`);
const response = JSON.parse(res.stdout);
console.log(res.stdout);
console.log(res.stderr);
assert.equal(response.outcome, 'success');
assert.match(res.stderr, /howdy, node/);
assert.strictEqual(res.error, null);
assert.match(res.stdout, /howdy, node/);
});
});
});
Expand Down Expand Up @@ -168,24 +167,24 @@ export function describeTests2({ text, options }: BuildKitOption) {
afterEach(async () => await devContainerDown({ composeProjectName }));
it('should have access to installed features (docker)', async () => {
const res = await shellExec(`${cli} exec --workspace-folder ${testFolder} docker --version`);
const response = JSON.parse(res.stdout);
console.log(res.stdout);
console.log(res.stderr);
assert.equal(response.outcome, 'success');
assert.match(res.stderr, /Docker version/);
assert.strictEqual(res.error, null);
assert.match(res.stdout, /Docker version/);
});
it('should have access to installed features (hello)', async () => {
const res = await shellExec(`${cli} exec --workspace-folder ${testFolder} hello`);
const response = JSON.parse(res.stdout);
console.log(res.stdout);
console.log(res.stderr);
assert.equal(response.outcome, 'success');
assert.match(res.stderr, /howdy, node/);
assert.strictEqual(res.error, null);
assert.match(res.stdout, /howdy, node/);
});
it('should have marker content', async () => {
const res = await shellExec(`${cli} exec --workspace-folder ${testFolder} cat /var/test-marker`);
const response = JSON.parse(res.stdout);
console.log(res.stdout);
console.log(res.stderr);
assert.equal(response.outcome, 'success');
assert.match(res.stderr, /||test-content||/);
assert.strictEqual(res.error, null);
assert.match(res.stdout, /||test-content||/);
});
});

Expand Down Expand Up @@ -234,8 +233,7 @@ export function describeTests2({ text, options }: BuildKitOption) {

// Should have Create + Start but not Attach
const res = await shellExec(`${cli} run-user-commands --skip-post-attach --workspace-folder ${testFolder}`);
const response = JSON.parse(res.stdout);
assert.equal(response.outcome, 'success');
assert.strictEqual(res.error, null);
await commandMarkerTests(cli, testFolder, { postCreate: true, postStart: true, postAttach: false }, 'Markers on run-user-commands');
});
});
Expand Down Expand Up @@ -333,17 +331,17 @@ export function describeTests2({ text, options }: BuildKitOption) {
afterEach(async () => await devContainerDown({ containerId }));
it('should have access to installed features (docker)', async () => {
const res = await shellExec(`${cli} exec --workspace-folder ${testFolder} docker --version`);
const response = JSON.parse(res.stdout);
console.log(res.stdout);
console.log(res.stderr);
assert.equal(response.outcome, 'success');
assert.match(res.stderr, /Docker version/);
assert.strictEqual(res.error, null);
assert.match(res.stdout, /Docker version/);
});
it('should have access to installed features (hello)', async () => {
const res = await shellExec(`${cli} exec --workspace-folder ${testFolder} hello`);
const response = JSON.parse(res.stdout);
console.log(res.stdout);
console.log(res.stderr);
assert.equal(response.outcome, 'success');
assert.match(res.stderr, /howdy, node/);
assert.strictEqual(res.error, null);
assert.match(res.stdout, /howdy, node/);
});
});

Expand All @@ -354,9 +352,7 @@ export function describeTests2({ text, options }: BuildKitOption) {
success = true;
} catch (error) {
assert.equal(error.error.code, 1, 'Should fail with exit code 1');
const res = JSON.parse(error.stdout);
assert.equal(res.outcome, 'error');
assert.match(res.message, /Dev container config \(.*\) not found./);
assert.match(error.stderr, /Dev container config \(.*\) not found./);
}
assert.equal(success, false, 'expect non-successful call');
});
Expand Down
12 changes: 6 additions & 6 deletions src/test/cli.set-up.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ describe('Dev Containers CLI', function () {
const containerId = (await shellExec(`docker run -d alpine:3.17 sleep inf`)).stdout.trim();

const res = await shellExec(`${cli} exec --container-id ${containerId} --config ${__dirname}/configs/set-up-with-config/devcontainer.json echo test-output`);
const response = JSON.parse(res.stdout);
console.log(res.stdout);
console.log(res.stderr);
assert.equal(response.outcome, 'success');
assert.match(res.stderr, /test-output/);
assert.strictEqual(res.error, null);
assert.match(res.stdout, /test-output/);

await shellExec(`docker rm -f ${containerId}`);
});
Expand All @@ -121,10 +121,10 @@ describe('Dev Containers CLI', function () {
const containerId = (await shellExec(`docker run -d devcontainer-set-up-test sleep inf`)).stdout.trim();

const res = await shellExec(`${cli} exec --container-id ${containerId} echo test-output`);
const response = JSON.parse(res.stdout);
console.log(res.stdout);
console.log(res.stderr);
assert.equal(response.outcome, 'success');
assert.match(res.stderr, /test-output/);
assert.strictEqual(res.error, null);
assert.match(res.stdout, /test-output/);

await shellExec(`docker rm -f ${containerId}`);
});
Expand Down
56 changes: 26 additions & 30 deletions src/test/container-features/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ describe('Dev Container Features E2E (remote)', function () {
success = true;
} catch (error) {
assert.equal(error.error.code, 1, 'Should fail with exit code 1');
const res = JSON.parse(error.stdout);
assert.equal(res.outcome, 'error');
// "Failed to fetch tarball" happens if the test is executed without a $GITHUB_TOKEN
// "HTTP 404: Not Found" happens if the test is executed with a $GITHUB_TOKEN
assert.ok(res.message.indexOf('Failed to fetch tarball') > -1 || res.message.indexOf('HTTP 404: Not Found') > -1, `Actual error msg: ${res.message}`);
assert.ok(error.stderr.indexOf('Failed to fetch tarball') > -1 || error.stderr.indexOf('HTTP 404: Not Found') > -1, `Actual error msg: ${error.stderr}`);
}
assert.equal(success, false, 'expect non-successful call');
});
Expand All @@ -48,9 +46,7 @@ describe('Dev Container Features E2E (remote)', function () {
success = true;
} catch (error) {
assert.equal(error.error.code, 1, 'Should fail with exit code 1');
const res = JSON.parse(error.stdout);
assert.equal(res.outcome, 'error');
assert.ok(res.message.indexOf('Failed to process feature') > -1, `Actual error msg: ${res.message}`);
assert.ok(error.stderr.indexOf('Failed to process feature') > -1, `Actual error msg: ${error.stderr}`);
}
assert.equal(success, false, 'expect non-successful call');
});
Expand All @@ -70,10 +66,10 @@ describe('Dev Container Features E2E (remote)', function () {
it('should detect docker installed (--privileged flag implicitly passed)', async () => {
// NOTE: Doing a docker ps will ensure that the --privileged flag was set by the feature
const res = await shellExec(`${cli} exec --workspace-folder ${testFolder} docker ps`);
const response = JSON.parse(res.stdout);
console.log(res.stdout);
console.log(res.stderr);
assert.equal(response.outcome, 'success');
assert.match(res.stderr, /CONTAINER ID/);
assert.isNull(res.error);
assert.match(res.stdout, /CONTAINER ID/);
});

it('should read configuration with features', async () => {
Expand Down Expand Up @@ -104,10 +100,10 @@ describe('Dev Container Features E2E (remote)', function () {
it('should detect docker installed (--privileged flag implicitly passed)', async () => {
// NOTE: Doing a docker ps will ensure that the --privileged flag was set by the feature
const res = await shellExec(`${cli} exec --workspace-folder ${testFolder} docker ps`);
const response = JSON.parse(res.stdout);
console.log(res.stdout);
console.log(res.stderr);
assert.equal(response.outcome, 'success');
assert.match(res.stderr, /CONTAINER ID/);
assert.isNull(res.error);
assert.match(res.stdout, /CONTAINER ID/);
});
});
});
Expand All @@ -133,10 +129,10 @@ describe('Dev Container Features E2E - local cache/short-hand notation', functio

it('should exec a PATH without the string \'ENV\'', async () => {
const res = await shellExec(`${cli} exec --workspace-folder ${testFolder} echo \${PATH}`);
const response = JSON.parse(res.stdout);
console.log(res.stdout);
console.log(res.stderr);
assert.equal(response.outcome, 'success');
assert.notMatch(res.stderr, /ENV/);
assert.isNull(res.error);
assert.notMatch(res.stdout, /ENV/);
});
});
});
Expand All @@ -162,10 +158,10 @@ describe('Dev Container Features E2E (local-path)', function () {

it('should exec the color command', async () => {
const res = await shellExec(`${cli} exec --workspace-folder ${testFolder} color`);
const response = JSON.parse(res.stdout);
console.log(res.stdout);
console.log(res.stderr);
assert.equal(response.outcome, 'success');
assert.match(res.stderr, /my favorite color is gold/);
assert.isNull(res.error);
assert.match(res.stdout, /my favorite color is gold/);
});
it('should read configuration with features', async () => {
const res = await shellExec(`${cli} read-configuration --workspace-folder ${testFolder} --include-features-configuration`);
Expand All @@ -183,18 +179,18 @@ describe('Dev Container Features E2E (local-path)', function () {

it('should exec the color command', async () => {
const res = await shellExec(`${cli} exec --workspace-folder ${testFolder} color`);
const response = JSON.parse(res.stdout);
console.log(res.stdout);
console.log(res.stderr);
assert.equal(response.outcome, 'success');
assert.match(res.stderr, /my favorite color is gold/);
assert.isNull(res.error);
assert.match(res.stdout, /my favorite color is gold/);
});

it('should exec the helloworld command', async () => {
const res = await shellExec(`${cli} exec --workspace-folder ${testFolder} hello`);
const response = JSON.parse(res.stdout);
console.log(res.stdout);
console.log(res.stderr);
assert.equal(response.outcome, 'success');
assert.match(res.stderr, /Hello there, vscode!!!!/);
assert.isNull(res.error);
assert.match(res.stdout, /Hello there, vscode!!!!/);
});

it('should read configuration with features', async () => {
Expand All @@ -213,18 +209,18 @@ describe('Dev Container Features E2E (local-path)', function () {

it('should exec the color commmand', async () => {
const res = await shellExec(`${cli} exec --workspace-folder ${testFolder} color`);
const response = JSON.parse(res.stdout);
console.log(res.stdout);
console.log(res.stderr);
assert.equal(response.outcome, 'success');
assert.match(res.stderr, /my favorite color is gold/);
assert.isNull(res.error);
assert.match(res.stdout, /my favorite color is gold/);
});

it('should exec the helloworld commmand', async () => {
const res = await shellExec(`${cli} exec --workspace-folder ${testFolder} hello`);
const response = JSON.parse(res.stdout);
console.log(res.stdout);
console.log(res.stderr);
assert.equal(response.outcome, 'success');
assert.match(res.stderr, /Hello there, vscode!!!!/);
assert.isNull(res.error);
assert.match(res.stdout, /Hello there, vscode!!!!/);
});

it('should read configuration with features with customizations', async () => {
Expand Down
Loading

0 comments on commit 488e6b1

Please sign in to comment.