summaryrefslogtreecommitdiff
path: root/test.lua
blob: d66f9776fe20625eab346dec10c2bef9dde9500b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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)