Commit 89c56f32 authored by Hunter Loftis's avatar Hunter Loftis

Merge pull request #194 from heroku/docker-tests

Docker tests
parents 197845da d2bb6c5b
......@@ -169,22 +169,21 @@ heroku config:set BUILDPACK_URL=<your-github-url>#your-branch
## Testing
[Anvil](https://github.com/ddollar/anvil) is a generic build server for Heroku.
The buildpack tests use [Docker](https://www.docker.com/) to simulate
Heroku's Cedar and Cedar-14 containers.
```
gem install anvil-cli
```
The [heroku-anvil CLI plugin](https://github.com/ddollar/heroku-anvil) is a wrapper for anvil.
To run the test suite:
```
heroku plugins:install https://github.com/ddollar/heroku-anvil
test/docker
```
The [ddollar/test](https://github.com/ddollar/buildpack-test) buildpack runs `bin/test` on your app/buildpack.
Or to just test in cedar or cedar-14:
```
heroku build -b ddollar/test # -b can also point to a local directory
test/docker cedar
test/docker cedar-14
```
For more info on testing, see [Best Practices for Testing Buildpacks](https://discussion.heroku.com/t/best-practices-for-testing-buildpacks/294) on the Heroku discussion forum.
The tests are run via the vendored [shunit2](http://shunit2.googlecode.com/svn/trunk/source/2.1/doc/shunit2.html)
test framework.
testConcurrency1X() {
MEMORY_AVAILABLE=512 capture ${bp_dir}/lib/concurrency.sh
assertCaptured "Detected 512 MB available memory, 512 MB limit per process (WEB_MEMORY)"
assertCaptured "Recommending WEB_CONCURRENCY=1"
assertCapturedSuccess
}
testConcurrency2X() {
MEMORY_AVAILABLE=1024 capture ${bp_dir}/lib/concurrency.sh
assertCaptured "Detected 1024 MB available memory, 512 MB limit per process (WEB_MEMORY)"
assertCaptured "Recommending WEB_CONCURRENCY=2"
assertCapturedSuccess
}
testConcurrencyPX() {
MEMORY_AVAILABLE=6144 capture ${bp_dir}/lib/concurrency.sh
assertCaptured "Detected 6144 MB available memory, 512 MB limit per process (WEB_MEMORY)"
assertCaptured "Recommending WEB_CONCURRENCY=12"
assertCapturedSuccess
}
testConcurrencyCustomLimit() {
MEMORY_AVAILABLE=1024 WEB_MEMORY=256 capture ${bp_dir}/lib/concurrency.sh
echo "This is STD_OUT:"
cat ${STD_OUT}
echo "This is STD_ERR:"
cat ${STD_ERR}
assertCaptured "Detected 1024 MB available memory, 256 MB limit per process (WEB_MEMORY)"
assertCaptured "Recommending WEB_CONCURRENCY=6"
assertCapturedSuccess
}
testConcurrencySaneMaximum() {
MEMORY_AVAILABLE=6144 WEB_MEMORY=32 capture ${bp_dir}/lib/concurrency.sh
assertCaptured "Detected 6144 MB available memory, 32 MB limit per process (WEB_MEMORY)"
assertCaptured "Recommending WEB_CONCURRENCY=32"
assertCapturedSuccess
}
......@@ -155,7 +155,7 @@ install_npm() {
info "npm `npm --version` already installed with node"
else
info "Downloading and installing npm $npm_engine (replacing version `npm --version`)..."
npm install --quiet -g npm@$npm_engine 2>&1 >/dev/null | indent
npm install --unsafe-perm --quiet -g npm@$npm_engine 2>&1 >/dev/null | indent
fi
warn_old_npm `npm --version`
else
......@@ -171,7 +171,7 @@ function build_dependencies() {
info "Rebuilding any native modules for this architecture"
npm rebuild 2>&1 | indent
info "Installing any new modules"
npm install --quiet --userconfig $build_dir/.npmrc 2>&1 | indent
npm install --unsafe-perm --quiet --userconfig $build_dir/.npmrc 2>&1 | indent
else
cache_status=$(get_cache_status)
......@@ -180,14 +180,14 @@ function build_dependencies() {
info "Restoring node modules from cache"
cp -r $cache_dir/node/node_modules $build_dir/
info "Pruning unused dependencies"
npm prune 2>&1 | indent
npm --unsafe-perm prune 2>&1 | indent
info "Installing any new modules"
npm install --quiet --userconfig $build_dir/.npmrc 2>&1 | indent
npm install --unsafe-perm --quiet --userconfig $build_dir/.npmrc 2>&1 | indent
else
info "$cache_status"
info "Installing node modules"
touch $build_dir/.npmrc
npm install --quiet --userconfig $build_dir/.npmrc 2>&1 | indent
npm install --unsafe-perm --quiet --userconfig $build_dir/.npmrc 2>&1 | indent
fi
fi
}
......
#!/usr/bin/env bash
cedar-14() {
echo "Running tests in docker (cedar-14)..."
docker run -v $(pwd):/buildpack:ro --rm -it heroku/cedar:14 bash -c 'cp -r /buildpack /buildpack_test; cd /buildpack_test/; test/run;'
echo ""
}
cedar() {
echo "Running tests in docker (cedar)..."
docker run -v $(pwd):/buildpack:ro --rm -it fabiokung/cedar bash -c 'cp -r /buildpack /buildpack_test; cd /buildpack_test/; test/run;'
}
if [ "$1" == "cedar-14" ]; then
cedar-14
elif [ "$1" == "cedar" ]; then
cedar
else
cedar-14
cedar
fi
{
"name": "node-buildpack-test-app",
"version": "0.0.1",
"description": "node buildpack integration test app",
"repository" : {
"type" : "git",
"url" : "http://github.com/example/example.git"
},
"engines": {
"node": "0.11.x"
}
}
......@@ -18,6 +18,13 @@ testDetectWithoutPackageJson() {
assertCapturedError 1 ""
}
testUnstableVersion() {
compile "unstable-version"
assertCaptured "Resolving node version 0.11.x via semver.io"
assertCaptured "Downloading and installing node 0.11"
assertCapturedSuccess
}
testBadJson() {
compile "bad-json"
assertCaptured "Build failed"
......@@ -61,12 +68,13 @@ testStableVersion() {
assertCapturedSuccess
}
testUnstableVersion() {
compile "unstable-version"
assertCaptured "Resolving node version >0.11.0 via semver.io"
assertCaptured "Downloading and installing node 0.11"
assertCapturedSuccess
}
testOldNpm() {
compile "old-npm"
......@@ -358,14 +366,13 @@ testMultiExport() {
assertCapturedSuccess
}
# Utils
pushd $(dirname 0) >/dev/null
bp_dir=$(pwd)
popd >/dev/null
source ${bp_dir}/vendor/test-utils/test-utils
source ${bp_dir}/test/utils
mktmpdir() {
dir=$(mktemp -t testXXXXX)
......@@ -375,14 +382,14 @@ mktmpdir() {
}
detect() {
capture ${bp_dir}/bin/detect ${bp_dir}/test/$1
capture ${bp_dir}/bin/detect ${bp_dir}/test/fixtures/$1
}
compile_dir=""
compile() {
compile_dir=$(mktmpdir)
cp -r ${bp_dir}/test/$1/. ${compile_dir}
cp -r ${bp_dir}/test/fixtures/$1/. ${compile_dir}
capture ${bp_dir}/bin/compile ${compile_dir} ${2:-$(mktmpdir)} $3
}
......@@ -390,4 +397,4 @@ assertFile() {
assertEquals "$1" "$(cat ${compile_dir}/$2)"
}
source ${bp_dir}/vendor/shunit2/shunit2
source ${bp_dir}/test/shunit2
{
"name": "node-buildpack-test-app",
"version": "0.0.1",
"description": "node buildpack integration test app",
"repository" : {
"type" : "git",
"url" : "http://github.com/example/example.git"
},
"engines": {
"node": ">0.11.0"
}
}
json: https://github.com/trentm/json
node-semver: http://github.com/isaacs/node-semver
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment