From 9855e635835716c638ab72c844d5dac08288a20c Mon Sep 17 00:00:00 2001 From: sanine Date: Sun, 22 May 2022 02:35:53 -0500 Subject: initial commit --- test.lua | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 test.lua (limited to 'test.lua') diff --git a/test.lua b/test.lua new file mode 100755 index 0000000..d66f977 --- /dev/null +++ b/test.lua @@ -0,0 +1,48 @@ +#!/usr/bin/lua + +local marigold = require 'marigold' + +function test(description, func) + io.write(description .. ': ') + local result, msg = pcall(func) + if result == true then + print("OK") + else + print("FAIL") + print(debug.traceback(msg)) + print() + end +end + +function test_assert(str) + local f = assert(loadstring('return ' .. str)) + assert(f(), 'assertion failed: ' .. str) +end + + +test("marigold.get_metavars correctly calls os.getenv", function() + -- mock os.getenv + local old_getenv = os.getenv + local env_tbl = { + AUTH_TYPE = 'some auth type', + CONTENT_LENGTH = 'a zillion', + GATEWAY_INTERFACE = 'idk, something', + PATH_INFO = 'youll see, its a secret', + PATH_TRANSLATED = 'i told you its a secret!', + QUERY_STRING = 'which string do you want?', + REMOTE_ADDR = 'probably somewhere in nunavut', + REMOTE_HOST = 'woah wait are we talking about parasites?', + REMOTE_IDENT = 'are you a cop?', + REMOTE_USER = 'seriously, you have to tell me if you are', + REQUEST_METHOD = 'uhh, to do what?', + SCRIPT_NAME = 'pretty sure this is hamlet', + SERVER_NAME = 'this isnt a restaurant', + SERVER_PROTOCOL = 'no really, not a restaurant', + SERVER_SOFTWARE = 'not familiar with that dish...', + } + os.getenv = function(varname) return env_tbl[varname] end + + -- actually call the function + --local metavars = marigold.get_metavars() + test_assert("type(metavars) == 'table'") +end) -- cgit v1.2.1