Skip to content

Commit

Permalink
nginx: add tests for config
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn authored and alxndrsn committed Sep 20, 2024
1 parent 4f69fcc commit b8572ab
Show file tree
Hide file tree
Showing 17 changed files with 1,911 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/test-nginx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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
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('/*', logRequestType('GET'));
app.post('/*', logRequestType('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 logRequestType(method) {
return withStdLogging((req, res) => {
requests.push({ method, path:req.path });
res.send('OK');
});
}
Loading

0 comments on commit b8572ab

Please sign in to comment.