Skip to content

Commit 929b430

Browse files
committed
Add a 'docker run' test for each language target
1 parent e173080 commit 929b430

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

test/interceptors/docker-terminal-interception.spec.ts

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as _ from 'lodash';
22
import * as path from 'path';
3+
import * as childProc from 'child_process';
34
import * as Docker from 'dockerode';
45

56
import { expect } from 'chai';
@@ -31,7 +32,59 @@ describe('Docker CLI interception', function () {
3132
await server.stop();
3233
});
3334

34-
it("should intercept 'docker run'", async () => {
35+
[
36+
'JS',
37+
'Java',
38+
'Python',
39+
'Ruby',
40+
'Go'
41+
].forEach((target) => {
42+
it(`should intercept 'docker run' of local ${target} containers`, async function () {
43+
this.timeout(60000);
44+
45+
// Build the target image (may already have been built by the attachment tests)
46+
const { exitCode: buildExitCode, stdout: buildStdout } = await spawnToResult(
47+
'docker', ['build', '.', '-q'],
48+
{ cwd: path.join(__dirname, '..', 'fixtures', 'docker', target.toLowerCase()) },
49+
true
50+
);
51+
52+
expect(buildExitCode).to.equal(0);
53+
const imageId = buildStdout.trim();
54+
55+
// Run the resulting container via the intercepting Docker proxy:
56+
const { server, httpsConfig} = await testSetup;
57+
const mainRule = await server.get('https://example.test').thenReply(200);
58+
59+
const terminalEnvOverrides = getTerminalEnvVars(server.port, httpsConfig, process.env, {}, {
60+
dockerEnabled: true
61+
});
62+
63+
childProc.spawn(
64+
'docker', ['run', '--rm', imageId, 'https://example.test'],
65+
{
66+
env: { ...process.env, ...terminalEnvOverrides },
67+
stdio: 'inherit'
68+
}
69+
);
70+
71+
await new Promise((resolve) => server.on('response', resolve));
72+
73+
const seenRequests = await mainRule.getSeenRequests();
74+
expect(seenRequests.map(r => r.url)).to.include('https://example.test/');
75+
76+
// Clean up the container (which will otherwise run forever):
77+
const docker = new Docker();
78+
const containers = await docker.listContainers({
79+
filters: JSON.stringify({ ancestor: [imageId] })
80+
});
81+
await Promise.all(
82+
containers.map((container) => docker.getContainer(container.Id).kill())
83+
);
84+
});
85+
});
86+
87+
it("should intercept 'docker run' launching a remote image", async () => {
3588
const { server, httpsConfig } = await testSetup;
3689

3790
const mainRule = await server.get("https://example.test").thenReply(200);

0 commit comments

Comments
 (0)