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 43 additions and 29 deletions
Showing only changes of commit 831a86c738 - Show all commits

View File

@ -7,8 +7,7 @@ events {
http {
server {
# listen 80;
listen 8080;
listen 80;
# listen 443 ssl;
include mime.types;
@ -34,7 +33,6 @@ http {
}
server {
listen 8080;
# listen 443 ssl;
server_name webdevcat.me;
@ -43,7 +41,7 @@ http {
default_type text/html;
location / {
return 301 http://miti.sh:8080$request_uri;
return 301 http://miti.sh$request_uri;
}
location ~ ^/git/(.*)$ {

View File

@ -1,31 +1,50 @@
http = require "luajit-curl-helper.http"
describe "routes", ->
it "loads miti.sh", ->
request = http.init "http://miti.sh:8080"
index_title = "miti.sh · Catalin Constantin Mititiuc"
req = (url) ->
request = http.init url
st = request\perform!
error request\lastError! if not st
request
status_code = request\statusCode!
status_message = request\statusMessage!
describe "http://webdevcat.me", ->
it "permanently redirects to http://miti.sh", ->
request = req "http://webdevcat.me"
assert.same request\statusCode!, 301
assert.same request\statusMessage!, "Moved Permanently"
assert.same request\header!.Location, "http://miti.sh/"
assert.same status_code, 200
assert.same status_message, "OK"
describe "http://webdevcat.me/git", ->
it "permanently redirects to http://git.miti.sh", ->
request = req "http://webdevcat.me/git"
assert.same request\header!.Location, "http://git.miti.sh/"
it "redirects webdevcat.me to miti.sh", ->
request = http.init "http://webdevcat.me:8080"
st = request\perform!
describe "http://webdevcat.me/git/", ->
it "permanently redirects to http://git.miti.sh", ->
request = req "http://webdevcat.me/git"
assert.same request\header!.Location, "http://git.miti.sh/"
error request\lastError! if not st
describe "http://webdevcat.me/git/pandoc/", ->
pending "permanently redirects to http://git.miti.sh/ccm/pandoc"
status_code = request\statusCode!
status_message = request\statusMessage!
header = request\header!
describe "http://miti.sh", ->
it "sends /index.html", ->
request = req "http://miti.sh"
assert.same request\statusCode!, 200
assert.same request\statusMessage!, "OK"
assert.same request\body!\match("<title>(.*)</title>"), index_title
assert.same status_code, 301
assert.same status_message, "Moved Permanently"
assert.same header.Location, "http://miti.sh:8080/"
describe "http://miti.sh/index", ->
it "sends /index.html", ->
request = req "http://miti.sh/index"
assert.same request\statusCode!, 200
assert.same request\statusMessage!, "OK"
assert.same request\body!\match("<title>(.*)</title>"), index_title
-- body = request\body!
-- print "body", body
describe "http://miti.sh/index.html", ->
it "sends /index.html", ->
request = req "http://miti.sh/index.html"
assert.same request\statusCode!, 200
assert.same request\statusMessage!, "OK"
assert.same request\body!\match("<title>(.*)</title>"), index_title

View File

@ -5,16 +5,13 @@
image=miti.sh
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 \
--add-host=miti.sh=127.0.0.1 \
--add-host=webdevcat.me=127.0.0.1 \
$image)
echo "Test container started"
# docker exec -t $container_id curl http://miti.sh:8080
# docker exec -t $container_id curl -v http://webdevcat.me:8080
docker exec -t $container_id busted
# echo "redirects webdevcat.me to miti.sh"