diff options
author | sanine <sanine.not@pm.me> | 2022-05-22 02:35:53 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2022-05-22 02:35:53 -0500 |
commit | 9855e635835716c638ab72c844d5dac08288a20c (patch) | |
tree | e2feb87779195165818acb69d0c1a4f998dae846 /test.lua |
initial commit
Diffstat (limited to 'test.lua')
-rwxr-xr-x | test.lua | 48 |
1 files changed, 48 insertions, 0 deletions
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) |