Add tests for nginx.conf directives #1

Merged
ccm merged 26 commits from ccm-test-nginx-directives into trunk 2025-06-14 21:54:22 +00:00
2 changed files with 32 additions and 72 deletions
Showing only changes of commit 11c56aff4d - Show all commits

View File

@ -15,13 +15,6 @@ http {
charset utf-8; charset utf-8;
default_type text/html; default_type text/html;
# ssl_certificate /var/www/certs/miti.sh/fullchain.pem;
# ssl_certificate_key /var/www/certs/miti.sh/privkey.pem;
location ^~ /.well-known/acme-challenge {
alias /var/www/dehydrated;
}
try_files $uri $uri/ $uri.html =404; try_files $uri $uri/ $uri.html =404;
# return `/posts/index.html` from `/posts` # return `/posts/index.html` from `/posts`
@ -41,41 +34,7 @@ http {
} }
server { server {
# listen 443 ssl; listen 8080;
server_name git.miti.sh;
location ^~ /.well-known/acme-challenge {
alias /var/www/dehydrated;
}
location / {
client_max_body_size 1024M;
proxy_pass http://localhost:3000;
proxy_set_header Connection $http_connection;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
server {
# listen 443 ssl;
server_name apps.miti.sh;
root /var/www/sites/apps.miti.sh;
include mime.types;
charset utf-8;
default_type text/html;
location ^~ /.well-known/acme-challenge {
alias /var/www/dehydrated;
}
}
server {
# listen 443 ssl; # listen 443 ssl;
server_name webdevcat.me; server_name webdevcat.me;
@ -83,15 +42,8 @@ http {
charset utf-8; charset utf-8;
default_type text/html; default_type text/html;
# ssl_certificate /var/www/certs/webdevcat.me/fullchain.pem;
# ssl_certificate_key /var/www/certs/webdevcat.me/privkey.pem;
location ^~ /.well-known/acme-challenge {
alias /var/www/dehydrated;
}
location / { location / {
return 301 https://miti.sh$request_uri; return 301 http://miti.sh:8080$request_uri;
} }
location ~ ^/git/(.*)$ { location ~ ^/git/(.*)$ {
@ -102,20 +54,4 @@ http {
return 301 https://apps.miti.sh/$1; return 301 https://apps.miti.sh/$1;
} }
} }
server {
# listen 443 ssl;
server_name git.webdevcat.me;
location ^~ /.well-known/acme-challenge {
alias /var/www/dehydrated;
}
}
server {
# listen 443 ssl;
server_name apps.webdevcat.me;
location ^~ /.well-known/acme-challenge {
alias /var/www/dehydrated;
}
}
} }

36
test.sh
View File

@ -4,14 +4,38 @@
# curl http://webdevcat.me:8080 # curl http://webdevcat.me:8080
image=miti.sh image=miti.sh
echo "starting container..." echo "Starting test container..."
container_id=$(docker run --rm -d -v $(pwd):/opt/app -p 8080:8080 \ container_id=$(docker run --rm -d -v $(pwd):/opt/app -p 8080:8080 \
--add-host=miti.sh=127.0.0.1 \ --add-host=miti.sh=127.0.0.1 \
--add-host=webdevcat.me=127.0.0.1 \ --add-host=webdevcat.me=127.0.0.1 \
$image) $image)
echo "container $container_id started" echo "Test container started"
echo "stopping container $container_id"
stop_cmd_result=$(docker stop $container_id) # docker exec -t $container_id curl http://miti.sh:8080
echo "container $stop_cmd_result stopped" # docker exec -t $container_id curl -v http://webdevcat.me:8080
# curl http://miti.sh:8080
echo "redirects webdevcat.me to miti.sh"
response=$(docker exec -t $container_id curl -so /dev/null \
-w "%{http_code} %{redirect_url}" http://webdevcat.me:8080)
expected="301 http://miti.sh:8080/"
if [[ $response != $expected ]]; then
echo "TEST FAILED"
printf "expected: $expected\ngot: $response\n"
else
echo "TEST PASSED"
fi
echo "Stopping test container"
docker exec $container_id openresty -p /opt/app -s stop
is_running=$(docker inspect -f '{{.State.Running}}' $container_id)
if [[ $is_running == "true" ]]; then
echo "Warning: Docker reports test container is still running"
else
echo "Test container stopped"
fi