Skip to content

Commit

Permalink
Added test harness
Browse files Browse the repository at this point in the history
  • Loading branch information
colincasey committed Mar 20, 2024
1 parent cc3d9bd commit ec971a4
Show file tree
Hide file tree
Showing 12 changed files with 1,714 additions and 62 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: CI

on:
push:
branches: ["main"]
pull_request:

permissions:
contents: read

jobs:
functional-test:
runs-on: ubuntu-22.04
container:
image: heroku/heroku:${{ matrix.stack_number }}-build
strategy:
matrix:
stack_number: ["20", "22"]
env:
STACK: heroku-${{ matrix.stack_number }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Functional tests on heroku:${{ matrix.stack_number }}-build
run: test/run
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
test: heroku-22-build heroku-20-build

heroku-22-build:
@echo "Running tests in docker (heroku-22-build)..."
@docker run -v $(shell pwd):/buildpack:ro --rm -it -e "STACK=heroku-22" heroku/heroku:22-build bash -c 'cp -r /buildpack /buildpack_test; cd /buildpack_test/; test/run;'
@echo ""

heroku-20-build:
@echo "Running tests in docker (heroku-20-build)..."
@docker run -v $(shell pwd):/buildpack:ro --rm -it -e "STACK=heroku-20" heroku/heroku:20-build bash -c 'cp -r /buildpack /buildpack_test; cd /buildpack_test/; test/run;'
@echo ""
59 changes: 0 additions & 59 deletions test/compile_test.sh

This file was deleted.

3 changes: 0 additions & 3 deletions test/fixtures/Aptfile/Aptfile

This file was deleted.

1 change: 1 addition & 0 deletions test/fixtures/custom-package-url-heroku-20/Aptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb
1 change: 1 addition & 0 deletions test/fixtures/custom-package-url-heroku-22/Aptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox_0.12.6.1-2.jammy_amd64.deb
2 changes: 2 additions & 0 deletions test/fixtures/custom-repository-heroku-20/Aptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:repo:deb http://us.archive.ubuntu.com/ubuntu/ focal multiverse
fasttracker2
2 changes: 2 additions & 0 deletions test/fixtures/custom-repository-heroku-22/Aptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:repo:deb http://us.archive.ubuntu.com/ubuntu/ jammy multiverse
fasttracker2
5 changes: 5 additions & 0 deletions test/fixtures/package-names/Aptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# single package
xmlsec1

# globbed package
mysql-client-*
112 changes: 112 additions & 0 deletions test/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/usr/bin/env bash

testCompilePackageNames() {
compile "package-names"
assertCaptured "Updating apt caches"
assertCaptured "Fetching .debs for xmlsec1"
assertCaptured "Fetching .debs for mysql-client-*"
assertCaptured "Installing xmlsec1"
assertCaptured "Installing mysql-client"
assertCaptured "Installing mysql-client-core"
assertCaptured "Writing profile script"
assertCaptured "Rewrite package-config files"
}

testReportPackageNames() {
report "package-names"
assertCaptured "packages: \"mysql-client-*,xmlsec1\""
assertNotCaptured "custom_packages"
assertNotCaptured "custom_repositories"
assertCapturedSuccess
}

testCompileCustomPackageUrl() {
declare -A download_urls=(
[heroku-20]="https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb"
[heroku-22]="https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox_0.12.6.1-2.jammy_amd64.deb"
)
compile "custom-package-url-$STACK"
assertCaptured "Updating apt caches"
assertCaptured "Fetching ${download_urls[$STACK]}"
assertCaptured "Installing wkhtmltox"
assertCaptured "Writing profile script"
assertCaptured "Rewrite package-config files"
}

testReportCustomPackageUrl() {
declare -A download_urls=(
[heroku-20]="https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb"
[heroku-22]="https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox_0.12.6.1-2.jammy_amd64.deb"
)
report "custom-package-url-$STACK"
assertNotCaptured "^packages"
assertCaptured "custom_packages: \"${download_urls[$STACK]}\""
assertNotCaptured "custom_repositories"
}

testCompileCustomRepository() {
declare -A ubuntu_release_names=(
[heroku-20]="focal"
[heroku-22]="jammy"
)
compile "custom-repository-$STACK"
assertCaptured "Adding custom repositories"
assertCaptured "Updating apt caches"
assertCaptured "http://us.archive.ubuntu.com/ubuntu ${ubuntu_release_names[$STACK]}/multiverse amd64 Packages"
assertCaptured "Fetching .debs for fasttracker2"
assertCaptured "Installing fasttracker2"
assertCaptured "Writing profile script"
assertCaptured "Rewrite package-config files"
}

testReportCustomRepository() {
declare -A ubuntu_release_names=(
[heroku-20]="focal"
[heroku-22]="jammy"
)
report "custom-repository-$STACK"
assertCaptured "packages: \"fasttracker2\""
assertNotCaptured "custom_packages"
assertCaptured "custom_repositories: \"deb http://us.archive.ubuntu.com/ubuntu/ ${ubuntu_release_names[$STACK]} multiverse\""
}

pushd "$(dirname 0)" >/dev/null || exit 1
popd >/dev/null || exit 1

source "$(pwd)"/test/utils

compile() {
default_process_types_cleanup
bp_dir=$(mktmpdir)
compile_dir=$(mktmpdir)
cp -a "$(pwd)"/* "${bp_dir}"
cp -a "${bp_dir}"/test/fixtures/"$1"/. "${compile_dir}"
capture "${bp_dir}"/bin/compile "${compile_dir}" "${2:-$(mktmpdir)}" "$3"
}

report() {
default_process_types_cleanup
compile_dir=${1:-$(mktmpdir)}
cache_dir=${2:-$(mktmpdir)}
env_dir=${3:-$(mktmpdir)}
bp_dir=$(mktmpdir)
cp -a "$(pwd)"/* "${bp_dir}"
cp -a "${bp_dir}"/test/fixtures/"$1"/. "${compile_dir}"
capture "${bp_dir}"/bin/report "${compile_dir}" "${cache_dir}" "${env_dir}"
}

mktmpdir() {
dir=$(mktemp -t testXXXXX)
rm -rf "$dir"
mkdir "$dir"
echo "$dir"
}

default_process_types_cleanup() {
file="/tmp/default_process_types"
if [ -f "$file" ]; then
rm "$file"
fi
}

source "$(pwd)"/test/shunit2
Loading

0 comments on commit ec971a4

Please sign in to comment.