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
3 changed files with 68 additions and 3 deletions
Showing only changes of commit 1e33d2770a - Show all commits

View File

@ -32,6 +32,21 @@ http {
}
}
server {
server_name git.miti.sh;
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 {
server_name apps.miti.sh;
root /var/www/sites/apps.miti.sh;
@ -57,4 +72,14 @@ http {
return 301 http://apps.miti.sh/$1;
}
}
server {
server_name git.webdevcat.me;
return 301 http://git.miti.sh$request_uri;
}
server {
server_name apps.webdevcat.me;
return 301 http://apps.miti.sh$request_uri;
}
}

View File

@ -10,9 +10,7 @@ req = (url) ->
describe "test environment", ->
it "can't connect to the internet", ->
request = http.init "http://example.org"
assert.not_true request\perform!
assert.same request\lastError!, "Couldn't resolve host name"
assert.has_error (-> req "http://example.org"), "Couldn't resolve host name"
describe "http://webdevcat.me", ->
it "permanently redirects to http://miti.sh", ->
@ -24,21 +22,50 @@ describe "http://webdevcat.me", ->
describe "http://webdevcat.me/git", ->
it "permanently redirects to http://git.miti.sh/ccm/", ->
request = req "http://webdevcat.me/git"
assert.same request\statusCode!, 301
assert.same request\statusMessage!, "Moved Permanently"
assert.same request\header!.Location, "http://git.miti.sh/ccm/"
describe "http://webdevcat.me/git/", ->
it "permanently redirects to http://git.miti.sh", ->
request = req "http://webdevcat.me/git"
assert.same request\statusCode!, 301
assert.same request\statusMessage!, "Moved Permanently"
assert.same request\header!.Location, "http://git.miti.sh/ccm/"
describe "http://webdevcat.me/git/pandoc", ->
it "permanently redirects to http://git.miti.sh/ccm/pandoc", ->
request = req "http://webdevcat.me/git/pandoc"
assert.same request\statusCode!, 301
assert.same request\statusMessage!, "Moved Permanently"
assert.same request\header!.Location, "http://git.miti.sh/ccm/pandoc"
describe "http://git.webdevcat.me", ->
it "permanently redirects to http://git.miti.sh/", ->
request = req "http://git.webdevcat.me"
assert.same request\statusCode!, 301
assert.same request\statusMessage!, "Moved Permanently"
assert.same request\header!.Location, "http://git.miti.sh/"
describe "http://webdevcat.me/apps/btroops", ->
it "permanently redirects to http://apps.miti.sh/btroops", ->
request = req "http://webdevcat.me/apps/btroops"
assert.same request\statusCode!, 301
assert.same request\statusMessage!, "Moved Permanently"
assert.same request\header!.Location, "http://apps.miti.sh/btroops"
describe "http://apps.webdevcat.me", ->
it "permanently redirects to http://apps.miti.sh/", ->
request = req "http://apps.webdevcat.me"
assert.same request\statusCode!, 301
assert.same request\statusMessage!, "Moved Permanently"
assert.same request\header!.Location, "http://apps.miti.sh/"
describe "http://apps.webdevcat.me/btroops", ->
it "permanently redirects to http://apps.miti.sh/btroops", ->
request = req "http://apps.webdevcat.me/btroops"
assert.same request\statusCode!, 301
assert.same request\statusMessage!, "Moved Permanently"
assert.same request\header!.Location, "http://apps.miti.sh/btroops"
describe "http://miti.sh", ->
@ -76,6 +103,14 @@ describe "http://miti.sh/posts", ->
assert.same request\statusMessage!, "OK"
assert.same request\body!\match("<title>(.*)</title>"), "miti.sh · Posts"
describe "http://git.miti.sh", ->
it "doesn't find it?", ->
request = req "http://git.miti.sh"
require("moon").p request\body!
require("moon").p request\header!
-- assert.same request\statusCode!, 404
-- assert.same request\statusMessage!, "Not Found"
describe "http://apps.miti.sh", ->
it "doesn't find it", ->
request = req "http://apps.miti.sh"

View File

@ -11,11 +11,16 @@ echo "Starting test container..."
container_id=$(docker run --rm -d -v $(pwd):/opt/app --network no-internet \
--add-host=miti.sh=127.0.0.1 \
--add-host=apps.miti.sh=127.0.0.1 \
--add-host=git.miti.sh=127.0.0.1 \
--add-host=webdevcat.me=127.0.0.1 \
--add-host=apps.webdevcat.me=127.0.0.1 \
--add-host=git.webdevcat.me=127.0.0.1 \
$image)
echo "Test container started"
# docker exec -t $container_id cat /etc/hosts
# docker exec -t $container_id cat /opt/app/logs/error.log
docker exec -t $container_id busted
# echo "redirects webdevcat.me to miti.sh"