Skip to content

Commit

Permalink
nginx-tests: eliminate duplicate dockerfile
Browse files Browse the repository at this point in the history
pros:

* nginx tests actually run against a real image

cons:

* slows fresh/CI builds by about 1 minute
  • Loading branch information
alxndrsn committed Oct 6, 2024
1 parent 60b354e commit fdba963
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 40 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/test-nginx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
submodules: recursive
- uses: actions/setup-node@v4
with:
node-version: 20.17.0
Expand Down
28 changes: 0 additions & 28 deletions test/nginx-test.dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion test/nginx.test.docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
nginx:
build:
context: ..
dockerfile: ./test/nginx-test.dockerfile
dockerfile: nginx.dockerfile
depends_on:
- service
- enketo
Expand Down
5 changes: 0 additions & 5 deletions test/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ wait_for_http_response() {
fi
}

log "Checking nginx dockerfiles have same base image..."
# It would be nice if Dockerfiles allowed some kind of templating which would
# allow for direct sharing between the real and test nginx dockerfiles.
diff <(grep FROM nginx-test.dockerfile) <(grep FROM ../nginx.dockerfile | grep -v AS)

log "Starting test services..."
docker_compose up --build --detach

Expand Down
13 changes: 7 additions & 6 deletions test/test-nginx.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,25 @@ describe('nginx config', () => {
});

[
'/index.html',
'/version.txt',
].forEach(staticFile => {
[ '/index.html', /<div id="app"><\/div>/ ],
[ '/version.txt', /^versions:/ ],
].forEach(([ staticFile, expectedContent ]) => {
it(`${staticFile} file should have no-cache header`, async () => {
// when
const res = await fetchHttps(staticFile);

// then
assert.isTrue(res.ok);
assert.equal(res.status, 200);
assert.equal(await res.text(), `hi:${staticFile}\n`);
assert.match(await res.text(), expectedContent);
assert.equal(await res.headers.get('cache-control'), 'no-cache');
});
});

[
'/should-be-cached.txt',
'/blank.html',
'/favicon.ico',
// there's no way to predict generated asset paths, as they have cache-busting names
].forEach(staticFile => {
it(`${staticFile} file should not have no-cache header`, async () => {
// when
Expand All @@ -72,7 +74,6 @@ describe('nginx config', () => {
// then
assert.isTrue(res.ok);
assert.equal(res.status, 200);
assert.equal(await res.text(), `hi:${staticFile}\n`);
assert.isNull(await res.headers.get('cache-control'));
});
});
Expand Down

0 comments on commit fdba963

Please sign in to comment.