Skip to content

Commit

Permalink
nginx: add tests for config (#715)
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn authored Sep 20, 2024
1 parent 4f69fcc commit 37e1287
Show file tree
Hide file tree
Showing 17 changed files with 1,918 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/test-nginx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Test nginx config

on:
push:
pull_request:

jobs:
build:
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: cd test && npm i
- run: cd test && ./run-tests.sh

- if: always()
run: docker logs test-nginx-1
- if: always()
run: docker logs test-service-1
- if: always()
run: docker logs test-enketo-1
1 change: 1 addition & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules/
1 change: 1 addition & 0 deletions test/files/nginx-test/acme-challenge
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hi-from-letsencrypt
1 change: 1 addition & 0 deletions test/files/nginx-test/http_root/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hi:/index.html
1 change: 1 addition & 0 deletions test/files/nginx-test/http_root/should-be-cached.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hi:/should-be-cached.txt
1 change: 1 addition & 0 deletions test/files/nginx-test/http_root/version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hi:/version.txt
1 change: 1 addition & 0 deletions test/mock-http-server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules/
37 changes: 37 additions & 0 deletions test/mock-http-server/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const express = require('express');

const port = process.env.PORT || 80;
const log = (...args) => console.log('[mock-http-server]', ...args);

const requests = [];

const app = express();

app.get('/health', withStdLogging((req, res) => res.send('OK')));
app.get('/request-log', withStdLogging((req, res) => res.json(requests)));
app.get('/reset', withStdLogging((req, res) => {
requests.length = 0;
res.json('OK');
}));

app.get('/*', ok('GET'));
app.post('/*', ok('POST'));
// TODO add more methods as required

app.listen(port, () => {
log(`Listening on port: ${port}`);
});

function withStdLogging(fn) {
return (req, res) => {
console.log(new Date(), req.method, req.path);
return fn(req, res);
};
}

function ok(method) {
return withStdLogging((req, res) => {
requests.push({ method, path:req.path });
res.send('OK');
});
}
Loading

0 comments on commit 37e1287

Please sign in to comment.