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 c368667 commit 74527f7
Show file tree
Hide file tree
Showing 19 changed files with 1,914 additions and 3 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
2 changes: 1 addition & 1 deletion nginx.dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:20.12.2-slim as intermediate
FROM node:20.12.2-slim AS intermediate

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
Expand Down
4 changes: 2 additions & 2 deletions service.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ARG node_version=20.12.2



FROM node:${node_version}-slim as pgdg
FROM node:${node_version}-slim AS pgdg
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
Expand All @@ -17,7 +17,7 @@ RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ $(grep -oP 'VERSION_CODEN



FROM node:${node_version}-slim as intermediate
FROM node:${node_version}-slim AS intermediate
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
git \
Expand Down
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 74527f7

Please sign in to comment.