miti.sh/spec/routes_spec.moon

131 lines
5.1 KiB
Plaintext

http = require "luajit-curl-helper.http"
index_title = "miti.sh · Catalin Constantin Mititiuc"
req = (url) ->
request = http.init url
st = request\perform!
error request\lastError! if not st
request
describe "test environment", ->
it "can't connect to the internet", ->
assert.has_error (-> req "http://example.org"), "Couldn't resolve host name"
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/"
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", ->
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
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
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
describe "http://miti.sh/posts/", ->
it "permanently redirects to http://miti.sh/posts", ->
request = req "http://miti.sh/posts/"
assert.same request\statusCode!, 301
assert.same request\statusMessage!, "Moved Permanently"
assert.same request\header!.Location, "http://miti.sh/posts"
describe "http://miti.sh/posts", ->
it "sends /posts/index.html", ->
request = req "http://miti.sh/posts"
assert.same request\statusCode!, 200
assert.same request\statusMessage!, "OK"
assert.same request\body!\match("<title>(.*)</title>"), "miti.sh · Posts"
describe "http://git.miti.sh", ->
it "reverse proxies request to gitea through a unix socket", ->
Path = require "sitegen.path"
socket_fname = "unixstreamsrvr.moon"
socket_dir = "/run/gitea"
socket_owner = "nobody"
basepath = Path.basepath debug.getinfo(1).short_src
os.execute "mkdir " .. socket_dir
p = io.popen "moon %s"\format Path.join(basepath, socket_fname)
os.execute "sleep 0.1"
os.execute "chown -R " .. socket_owner .. " " .. socket_dir
result = Path.read_exec "find", socket_dir, "-type", "s", "-ls"
assert.truthy result\match "nobody%s+root.+" .. Path.join(socket_dir, "gitea.socket")
request = req "http://git.miti.sh"
pout = p\read"*a"
p\close!
assert.truthy pout\match "Host: git.miti.sh"
describe "http://apps.miti.sh", ->
it "doesn't find it", ->
request = req "http://apps.miti.sh"
assert.same request\statusCode!, 404
assert.same request\statusMessage!, "Not Found"