Skip to content

Commit f38ac97

Browse files
authored
Fix issues in integration tests that should have never passed (#263)
1 parent 6dbeb52 commit f38ac97

File tree

2 files changed

+47
-24
lines changed

2 files changed

+47
-24
lines changed

packages/vscode-container-client/src/test/ContainerOrchestratorClientE2E.test.ts

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ describe('(integration) ContainerOrchestratorClientE2E', function () {
2727
let containerClient: DockerClient;
2828
let defaultRunner: ICommandRunnerFactory;
2929
let defaultRunnerFactory: (options: ShellStreamCommandRunnerOptions) => ICommandRunnerFactory;
30-
let composeFilePath: string;
3130
let composeDir: string;
32-
let composeProfileFilePath: string;
31+
let composeFilePath: string;
32+
let composeWithLogsFilePath: string;
33+
let composeWithProfilesFilePath: string;
3334

3435
this.timeout(10000); // Set a longer timeout for integration tests
3536

@@ -45,20 +46,23 @@ describe('(integration) ContainerOrchestratorClientE2E', function () {
4546

4647
defaultRunner = defaultRunnerFactory({ strict: true, });
4748

48-
// Set up paths for test docker-compose file
49+
// Set up paths for test docker-compose files
4950
composeDir = path.resolve(__dirname, 'buildContext');
5051
composeFilePath = path.resolve(composeDir, 'docker-compose.yml');
51-
composeProfileFilePath = path.resolve(composeDir, 'docker-compose.profiles.yml');
52+
composeWithLogsFilePath = path.resolve(composeDir, 'docker-compose.logs.yml');
53+
composeWithProfilesFilePath = path.resolve(composeDir, 'docker-compose.profiles.yml');
5254

53-
// Create the test docker-compose.yml file
55+
// Create the test docker-compose.yml files
5456
await fs.mkdir(composeDir, { recursive: true });
5557
await fs.writeFile(composeFilePath, TestComposeFileContent);
56-
await fs.writeFile(composeProfileFilePath, TestComposeFileContentWithProfiles);
58+
await fs.writeFile(composeWithLogsFilePath, TestComposeWithLogsFileContent);
59+
await fs.writeFile(composeWithProfilesFilePath, TestComposeWithProfilesFileContent);
5760

5861
if (runInWsl) {
5962
composeDir = wslifyPath(composeDir);
6063
composeFilePath = wslifyPath(composeFilePath);
61-
composeProfileFilePath = wslifyPath(composeProfileFilePath);
64+
composeWithLogsFilePath = wslifyPath(composeWithLogsFilePath);
65+
composeWithProfilesFilePath = wslifyPath(composeWithProfilesFilePath);
6266
}
6367
});
6468

@@ -68,7 +72,8 @@ describe('(integration) ContainerOrchestratorClientE2E', function () {
6872
await defaultRunner.getCommandRunner()(
6973
client.down({
7074
files: [composeFilePath],
71-
removeVolumes: true
75+
removeVolumes: true,
76+
timeoutSeconds: 1,
7277
})
7378
);
7479
} catch (error) {
@@ -130,6 +135,7 @@ describe('(integration) ContainerOrchestratorClientE2E', function () {
130135
client.down({
131136
files: [composeFilePath],
132137
removeVolumes: true,
138+
timeoutSeconds: 1,
133139
})
134140
);
135141

@@ -155,6 +161,7 @@ describe('(integration) ContainerOrchestratorClientE2E', function () {
155161
await defaultRunner.getCommandRunner()(
156162
client.stop({
157163
files: [composeFilePath],
164+
timeoutSeconds: 1,
158165
})
159166
);
160167
});
@@ -200,6 +207,7 @@ describe('(integration) ContainerOrchestratorClientE2E', function () {
200207
await defaultRunner.getCommandRunner()(
201208
client.stop({
202209
files: [composeFilePath],
210+
timeoutSeconds: 1,
203211
})
204212
);
205213

@@ -236,6 +244,7 @@ describe('(integration) ContainerOrchestratorClientE2E', function () {
236244
await defaultRunner.getCommandRunner()(
237245
client.restart({
238246
files: [composeFilePath],
247+
timeoutSeconds: 1,
239248
})
240249
);
241250

@@ -261,17 +270,27 @@ describe('(integration) ContainerOrchestratorClientE2E', function () {
261270
// Ensure services are up before logs test
262271
await defaultRunner.getCommandRunner()(
263272
client.up({
264-
files: [composeFilePath],
273+
files: [composeWithLogsFilePath],
265274
detached: true,
266275
})
267276
);
268277
});
269278

279+
after('Logs', async function () {
280+
// Ensure services are down after logs test
281+
await defaultRunner.getCommandRunner()(
282+
client.down({
283+
files: [composeWithLogsFilePath],
284+
timeoutSeconds: 1,
285+
})
286+
);
287+
});
288+
270289
it('LogsCommand', async function () {
271290
// Get logs without following
272291
const logsStream = defaultRunner.getStreamingCommandRunner()(
273292
client.logs({
274-
files: [composeFilePath],
293+
files: [composeWithLogsFilePath],
275294
follow: false,
276295
tail: 10,
277296
})
@@ -322,7 +341,7 @@ describe('(integration) ContainerOrchestratorClientE2E', function () {
322341
// The test docker-compose.yml doesn't define profiles, but the command should still work
323342
const profiles = await defaultRunner.getCommandRunner()(
324343
client.config({
325-
files: [composeFilePath, composeProfileFilePath],
344+
files: [composeFilePath, composeWithProfilesFilePath],
326345
configType: 'profiles',
327346
})
328347
);
@@ -354,16 +373,24 @@ services:
354373
image: alpine:latest
355374
volumes:
356375
- test-volume:/test-volume
376+
tty: true # Will keep the container running
357377
358378
backend:
359379
image: alpine:latest
360-
entrypoint: ["echo", "Log entry for testing"]
380+
entrypoint: ["tail", "-f", "/dev/null"] # Another way to keep the container running
361381
362382
volumes:
363383
test-volume:
364384
`;
365385

366-
const TestComposeFileContentWithProfiles = `
386+
const TestComposeWithLogsFileContent = `
387+
services:
388+
serviceWithLogs:
389+
image: alpine:latest
390+
entrypoint: ["echo", "Log entry for testing"]
391+
`;
392+
393+
const TestComposeWithProfilesFileContent = `
367394
services:
368395
frontend:
369396
profiles:

packages/vscode-container-client/src/test/ContainersClientE2E.test.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { ShellStreamCommandRunnerFactory, ShellStreamCommandRunnerOptions } from
1515
import { WslShellCommandRunnerFactory, WslShellCommandRunnerOptions } from '../commandRunners/wslStream';
1616
import { IContainersClient, ListContainersItem, ListImagesItem, ListNetworkItem, ListVolumeItem, StatPathItem } from '../contracts/ContainerClient';
1717
import { CommandResponseBase, ICommandRunnerFactory } from '../contracts/CommandRunner';
18-
import { isCommandNotSupportedError } from '../utils/CommandNotSupportedError';
1918
import { Bash } from '../utils/spawnStreamAsync';
2019
import { wslifyPath } from '../utils/wslifyPath';
2120

@@ -459,17 +458,14 @@ describe('(integration) ContainersClientE2E', function () {
459458
});
460459

461460
it('StatsContainersCommand', async function () {
462-
// Not implemented, so expect it to throw
463-
try {
464-
await defaultRunner.getCommandRunner()(
465-
client.statsContainers({ containers: [testContainerId] })
466-
);
467-
} catch (error) {
468-
expect(isCommandNotSupportedError(error)).to.be.true;
469-
return;
470-
}
461+
// Since we can't actually run stats (it runs forever), we'll just verify the command generation
462+
const command = await client.statsContainers({ all: true });
463+
expect(command).to.be.ok;
464+
expect(command.command).to.be.a('string');
465+
expect(command.args).to.be.an('array');
471466

472-
expect.fail('Expected error not thrown');
467+
// We expect `container stats --all`
468+
expect(getBashCommandLine(command)).to.equal(`${client.commandName} container stats --all`);
473469
});
474470

475471
it('RemoveContainersCommand', async function () {

0 commit comments

Comments
 (0)