Skip to content

Commit 1b7b601

Browse files
committed
Revamp scripts and tests to allow for easy addition of different docker images
1 parent 13a8f7d commit 1b7b601

15 files changed

+111
-9
lines changed

.travis.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,11 @@ node_js:
55
services:
66
- docker
77

8-
before_install:
9-
- docker build -t postman/newman_ubuntu1404 ./ubuntu_1404
10-
118
install:
129
- npm install
1310

1411
script:
1512
- npm test
16-
- docker run -v $PWD/tests/data:/etc/newman -t postman/newman_ubuntu1404 -c HTTPBinNewmanTest.json.postman_collection -e HTTPBinNewmanTestEnv.json.postman_environment --exitCode
17-
- docker run -t postman/newman_ubuntu1404 -u https://www.getpostman.com/collections/8a0c9bc08f062d12dcda --exitCode
1813

1914
after_success:
2015
- echo "All done!"
File renamed without changes.
File renamed without changes.
File renamed without changes.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
"version": "2.1.1",
44
"description": "This repository contains the Dockerfiles and tests for the Newman Docker images.",
55
"scripts": {
6-
"test": "mocha tests/*-spec.js"
6+
"docker-build": "./scripts/docker/docker-build.sh",
7+
"docker-test": "./scripts/docker/docker-test.sh",
8+
"test": "./scripts/test/test.sh",
9+
"test-docker": "./scripts/test/test-docker.sh",
10+
"test-infra": "./scripts/test/test-infra.sh"
711
},
812
"repository": {
913
"type": "git",

scripts/docker/docker-build.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
set -e;
4+
5+
IMAGES_BASE_PATH="./images";
6+
7+
function build_docker_image {
8+
TAG=$(grep -oP "(?<=ENV\ NEWMAN_VERSION\ ).+" ${1}/Dockerfile);
9+
BASENAME=$(basename $1);
10+
docker build -t postman/newman_${BASENAME}:${TAG} ${1};
11+
}
12+
13+
if [ -z "$1" ]; then
14+
for image in $IMAGES_BASE_PATH/*; do
15+
if [ -d "${image}" ] && [ -f "${image}/Dockerfile" ]; then
16+
build_docker_image ${image};
17+
fi
18+
done
19+
else
20+
if [ -d "${IMAGES_BASE_PATH}/${1}" ] && [ -f "${IMAGES_BASE_PATH}/${1}/Dockerfile" ]; then
21+
build_docker_image ${IMAGES_BASE_PATH}/${1};
22+
else
23+
echo "Invalid image";
24+
exit 1;
25+
fi
26+
fi

scripts/docker/docker-test.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
set -e;
4+
5+
IMAGES_BASE_PATH="./images";
6+
7+
function test_docker_image {
8+
TAG=$(grep -oP "(?<=ENV\ NEWMAN_VERSION\ ).+" ${1}/Dockerfile);
9+
BASENAME=$(basename $1);
10+
11+
docker run -v $PWD/test/data:/etc/newman -t postman/newman_${BASENAME}:${TAG} \
12+
-c HTTPBinNewmanTest.json.postman_collection \
13+
-e HTTPBinNewmanTestEnv.json.postman_environment \
14+
--exitCode;
15+
16+
docker run -t postman/newman_${BASENAME}:${TAG} \
17+
-u https://www.getpostman.com/collections/8a0c9bc08f062d12dcda \
18+
--exitCode;
19+
}
20+
21+
if [ -z "$1" ]; then
22+
for image in $IMAGES_BASE_PATH/*; do
23+
if [ -d "${image}" ] && [ -f "${image}/Dockerfile" ]; then
24+
test_docker_image ${image};
25+
fi
26+
done
27+
else
28+
if [ -d "${IMAGES_BASE_PATH}/${1}" ] && [ -f "${IMAGES_BASE_PATH}/${1}/Dockerfile" ]; then
29+
test_docker_image ${IMAGES_BASE_PATH}/${1};
30+
else
31+
echo "Invalid image";
32+
exit 1;
33+
fi
34+
fi

scripts/test/test-docker.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
# stop on first error
4+
set -e;
5+
6+
echo -e "\n\n\033[93mBuilding docker images...\033[0m";
7+
npm run docker-build;
8+
9+
echo -e "\n\n\033[93mTesting docker images...\033[0m";
10+
npm run docker-test;

scripts/test/test-infra.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
# stop on first error
4+
set -e;
5+
6+
echo -e "\n\n\033[93mRunning infrastructure tests...\033[0m";
7+
echo -e "\033[0m\033[2mmocha `mocha --version`\033[0m";
8+
9+
# run mocha tests
10+
mocha test/infra/**/*.test.js --recursive;

scripts/test/test.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
set -e;
4+
5+
echo "";
6+
echo " ,-————,";
7+
echo " / _____ \\";
8+
echo " ( | > | )";
9+
echo " \\ — /";
10+
echo " \`—————‘";
11+
echo "";
12+
13+
echo "Newman Docker Tests";
14+
15+
# run infra tests
16+
npm run test-infra;
17+
18+
# run docker tests
19+
npm run test-docker;
File renamed without changes.

tests/dockerfiles-spec.js renamed to test/infra/dockerfiles.test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,21 @@ var expect = require('expect.js'),
99

1010
/* global describe, it */
1111
describe('Validate Dockerfiles', function () {
12-
var versions = ['ubuntu_1404'],
12+
var imagesBaseDirectory = path.join(__dirname, '../../images'),
13+
versions = fs.readdirSync(imagesBaseDirectory).filter(function (item) {
14+
return fs.statSync(path.join(imagesBaseDirectory, item)).isDirectory();
15+
}),
1316
rules = fs.readFileSync(path.join(__dirname, 'dockerfile_rules.yml')),
14-
validator = new DockerFileValidator(rules); // TODO: Decide how we want to automatically load versions.
17+
validator = new DockerFileValidator(rules);
1518

1619
versions.map(function (version) {
17-
var dockerFilePath = path.join(__dirname, '..', version, 'Dockerfile'),
20+
var dockerFilePath = path.join(imagesBaseDirectory, version, 'Dockerfile'),
1821
dockerFileContent = fs.readFileSync(dockerFilePath);
1922

2023
it('Docker file for "' + version + '" must be valid', function () {
2124
var result = validator.validate(dockerFileContent.toString()),
2225
numBadThings = result.error.count + result.warn.count;
26+
2327
if (!(numBadThings == 0)) {
2428
console.log(JSON.stringify(result, null, 4)); // Helps debugging on the CI
2529
}

0 commit comments

Comments
 (0)