Skip to content

Commit 2e789a5

Browse files
committed
Add test cases
1 parent d1cbe57 commit 2e789a5

10 files changed

Lines changed: 88 additions & 1 deletion

File tree

src/test/configs/podman-with-cpp/.devcontainer.json renamed to src/test/configs/preprocessdocker-with-cpp/.devcontainer.json

File renamed without changes.
File renamed without changes.

src/test/configs/podman-with-cpp/common.Dockerfile renamed to src/test/configs/preprocessdocker-with-cpp/common.Dockerfile

File renamed without changes.
File renamed without changes.

src/test/configs/podman-with-cpp/tools.Dockerfile renamed to src/test/configs/preprocessdocker-with-cpp/tools.Dockerfile

File renamed without changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#define BASE_IMAGE ubuntu:20.04
2+
#define INSTALL_NODE
3+
#define INSTALL_PYTHON
4+
5+
FROM BASE_IMAGE
6+
7+
#ifdef INSTALL_NODE
8+
RUN apt-get update && apt-get install -y nodejs
9+
#endif
10+
11+
#ifdef INSTALL_PYTHON
12+
RUN apt-get update && apt-get install -y python3
13+
#endif
14+
15+
#include "common.Dockerfile"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
RUN apt-get update && apt-get install -y curl wget
2+
3+
ENV APP_ENV=development
4+
ENV APP_DEBUG=true
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "Node.js & Mongo DB",
3+
"dockerComposeFile": "docker-compose.yml",
4+
"service": "app",
5+
"workspaceFolder": "/workspace"
6+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: '3.8'
2+
3+
services:
4+
app:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile.in
8+
# Overrides default command so things don't shut down after the process ends.
9+
command: sleep infinity
10+
db:
11+
image: mongo:latest
12+
restart: unless-stopped
13+
volumes:
14+
- mongodb-data:/data/db
15+
16+
volumes:
17+
mongodb-data: null
Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ import * as path from 'path';
1010
import { ExecFunction, plainExec } from '../spec-common/commonUtils';
1111
import { nullLog } from '../spec-utils/log';
1212
import { ensureDockerfileHasFinalStageName, preprocessDockerfileIn } from '../spec-node/dockerfileUtils';
13+
import { shellExec } from './testUtils';
1314

1415
describe('preprocessDockerfileIn', () => {
1516
// Use the actual Dockerfile.in from the podman-with-cpp config directory.
1617
// It defines BASE_IMAGE, INSTALL_NODE, and INSTALL_PYTHON macros, uses
1718
// #ifdef/#endif blocks, and #includes common.Dockerfile and tools.Dockerfile.
18-
const configDir = path.join(__dirname, 'configs', 'podman-with-cpp');
19+
const configDir = path.join(__dirname, 'configs', 'preprocessdocker-with-cpp');
1920
const dockerfileInPath = path.join(configDir, 'Dockerfile.in');
2021

2122
let tmpDir: string;
@@ -118,3 +119,47 @@ describe('preprocessDockerfileIn', () => {
118119
});
119120
});
120121
});
122+
123+
describe('preprocess Docker Compose config', function () {
124+
this.timeout('240s');
125+
126+
const cli = 'node ./dist/spec-node/devContainersSpecCLI.js';
127+
const containerEngine = 'docker';
128+
const workspaceFolder = path.join(__dirname, 'configs', 'preprocessdockercompose-with-cpp');
129+
130+
let containerId: string | undefined;
131+
let composeProjectName: string | undefined;
132+
let outcome: string | undefined;
133+
134+
before(async () => {
135+
const res = await shellExec(`${cli} up --workspace-folder ${workspaceFolder}`);
136+
const response = JSON.parse(res.stdout);
137+
138+
outcome = response.outcome;
139+
containerId = response.containerId;
140+
composeProjectName = response.composeProjectName;
141+
});
142+
143+
after(async () => {
144+
if (composeProjectName) {
145+
await shellExec(`${containerEngine} compose --project-name ${composeProjectName} down -v`, undefined, true, true);
146+
}
147+
if (containerId) {
148+
await shellExec(`${containerEngine} rm -f ${containerId}`, undefined, true, true);
149+
}
150+
});
151+
152+
it('should execute successfully for a docker-compose config that builds from Dockerfile.in', () => {
153+
assert.equal(outcome, 'success');
154+
assert.isDefined(containerId);
155+
assert.isDefined(composeProjectName);
156+
});
157+
158+
it('should build the service from preprocessed Dockerfile.in content', async () => {
159+
const res = await shellExec(`${containerEngine} exec ${containerId} sh -lc \"command -v python3 && command -v curl && command -v wget\"`);
160+
161+
assert.include(res.stdout, 'python3');
162+
assert.include(res.stdout, 'curl');
163+
assert.include(res.stdout, 'wget');
164+
});
165+
});

0 commit comments

Comments
 (0)