Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding some simple tests using bats-core #47

Merged
merged 2 commits into from
Aug 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ blocks:
commands:
# Authenticate to the registry for all jobs in the block
- echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin
- git clone https://github.com/bats-core/bats-core.git
- cd bats-core
- sudo ./install.sh /usr/local
jobs:
- name: Tests
commands:
- checkout
- sudo bats tests
- name: Docker build
commands:
- checkout
Expand Down
68 changes: 68 additions & 0 deletions tests/nginx-proxy.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env bats

BASE=recipes/docker-compose/simple
setup () {
if [[ "$BATS_TEST_NUMBER" -eq 1 ]]; then
docker-compose -f $BASE/docker-compose.yml up -d
timeout 2m bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/healthcheck)" != "200" ]]; do sleep 5; done' || false
rm -rf $BASE/data/*
fi
}

@test "PNG returns an image/png content-type" {
curl -sSL -D - http://localhost/unsafe/500x150/i.imgur.com/Nfn80ck.png -o /dev/null |grep 'Content-Type: image/png'
}

@test "PNG result is cached" {
ls $BASE/data/result_storage/default/8b/83/b846d9575c01f23bff9f430d5f81f16c44cb
curl -sSL -D - http://localhost/unsafe/500x150/i.imgur.com/Nfn80ck.png -o /dev/null |grep 'Content-Type: image/png'
}

@test "next PNG request is fetched from cache" {
echo 1234 > $BASE/data/result_storage/default/8b/83/b846d9575c01f23bff9f430d5f81f16c44cb
curl -H -sSL -D - http://localhost/unsafe/500x150/i.imgur.com/Nfn80ck.png |tail -1 |grep 1234
}

@test "AUTO_WEBP returns an image/webp image" {
curl -H 'Accept: image/webp' -sSL -D - http://localhost/unsafe/500x150/i.imgur.com/Nfn80ck.png -o /dev/null |grep 'Content-Type: image/webp'
}

@test "AUTO_WEBP result is cached" {
ls $BASE/data/result_storage/auto_webp/8b/83/b846d9575c01f23bff9f430d5f81f16c44cb
curl -H 'Accept: image/webp' -sSL -D - http://localhost/unsafe/500x150/i.imgur.com/Nfn80ck.png -o /dev/null |grep 'Content-Type: image/webp'
}

@test "next WEBP request is fetched from cache" {
echo 1234 > $BASE/data/result_storage/auto_webp/8b/83/b846d9575c01f23bff9f430d5f81f16c44cb
curl -H 'Accept: image/webp' -sSL -D - http://localhost/unsafe/500x150/i.imgur.com/Nfn80ck.png |tail -1 |grep 1234
}

@test "filters:format(jpeg) returns an image/jpeg content-type" {
rm -f $BASE/data/result_storage/default/8b/83/b846d9575c01f23bff9f430d5f81f16c44cb
curl -sSL -D - 'http://localhost/unsafe/500x150/filters:format(jpeg)/i.imgur.com/Nfn80ck.png' -o /dev/null |grep 'Content-Type: image/jpeg'
}

@test "filters:format(jpeg) result is cached" {
ls $BASE/data/result_storage/default/77/1f/8c8786e4ad7ed364b2ea722fbe8f3ec043b6
curl -sSL -D - 'http://localhost/unsafe/500x150/filters:format(jpeg)/i.imgur.com/Nfn80ck.png' -o /dev/null |grep 'Content-Type: image/jpeg'
}

@test "next filters:format(jpeg) request is fetched from cache" {
echo 1234 > $BASE/data/result_storage/default/77/1f/8c8786e4ad7ed364b2ea722fbe8f3ec043b6
curl -sSL -D - 'http://localhost/unsafe/500x150/filters:format(jpeg)/i.imgur.com/Nfn80ck.png' |tail -1 |grep 1234
}

@test "filters:format(webp) returns an image/webp content-type" {
rm -f $BASE/data/result_storage/default/a4/5a/9b7ed7290937d3c996c178141ae5517f8567
curl -sSL -D - 'http://localhost/unsafe/500x150/filters:format(webp)/i.imgur.com/Nfn80ck.png' -o /dev/null |grep 'Content-Type: image/webp'
}

@test "filters:format(webp) result is cached" {
ls $BASE/data/result_storage/default/a4/5a/9b7ed7290937d3c996c178141ae5517f8567
curl -sSL -D - 'http://localhost/unsafe/500x150/filters:format(webp)/i.imgur.com/Nfn80ck.png' -o /dev/null |grep 'Content-Type: image/webp'
}

@test "next filters:format(webp) request is fetched from cache" {
echo 1234 > $BASE/data/result_storage/default/a4/5a/9b7ed7290937d3c996c178141ae5517f8567
curl -sSL -D - 'http://localhost/unsafe/500x150/filters:format(webp)/i.imgur.com/Nfn80ck.png' |tail -1 |grep 1234
}