-- Listen on localhost
-if not next(net.list()) then
+if not next(net.list()) and not env.TEST then
local ok, err = pcall(net.listen, '127.0.0.1')
if not ok then
error('bind to 127.0.0.1@53 '..err)
--- /dev/null
+dofile('./test_utils.lua') -- load test utilities
+
+-- setup resolver
+modules = { 'predict' }
+
+-- test if prediction of non-standard types works
+function test_predict_drain_typex()
+ predict.queue_len = 1
+ predict.queue['TYPE65535 example.com'] = 1
+ predict.drain()
+end
+
+-- run test after processed config file
+-- default config will be used and we can test it.
+event.after(0, function (ev)
+ test(test_predict_drain_typex)
+ quit()
+end)
--- /dev/null
+#!/bin/sh -e
+export TMP_RUNDIR=`mktemp -d`
+function finish {
+ rm -rf ${TMP_RUNDIR}
+}
+trap finish EXIT
+
+echo "config-test: ${2}"
+cp tests/config/${2}/* ${TMP_RUNDIR}/
+cp tests/config/test_utils.lua ${TMP_RUNDIR}/
+TEST=1 ${1} -f 1 -c test.cfg ${TMP_RUNDIR}
\ No newline at end of file
# Run kresd in temp directory and use config test.cfg
# Check return code of kresd. Passed test have to call quit().
-tests_lua := \
- hints
+tests_config := \
+ hints \
+ predict
-check-config: check-install-precond
- $(foreach test,$(tests_lua), \
- @echo "config-test: $(test)" ;\
- export TMP_RUNDIR=`mktemp -d` ;\
- cp "tests/config/$(test)"/* $${TMP_RUNDIR} ;\
- cp tests/config/test_utils.lua $${TMP_RUNDIR} ;\
- $(preload_syms) $(DEBUGGER) $(abspath $(SBINDIR)/kresd) -c test.cfg $${TMP_RUNDIR} > /dev/null ;\
- export retval=$$? ;\
- rm -rf $${TMP_RUNDIR} ;\
- test $${retval} -eq 0 ;\
- )
+define make_config_test
+test-config-$(1): tests/config/$(1)/test.cfg check-install-precond
+ @$(preload_syms) $(DEBUGGER) ./tests/config/runtest.sh $(abspath $(SBINDIR)/kresd) $(1)
+.PHONY: test-$(1)
+endef
+
+$(foreach test,$(tests_config),$(eval $(call make_config_test,$(test))))
+check-config: $(foreach test,$(tests_config),test-config-$(test))
.PHONY: check-config
function fail(fmt, ...)
- io.stderr:write(string.format(fmt..'\n', ...))
+ io.stderr:write(string.format(fmt..'\n', ...))
os.exit(2)
end
+function test(f, ...)
+ local res, exception = pcall(f, ...)
+ if not res then
+ local trace = debug.getinfo(2)
+ fail('%s:%d %s', trace.source, trace.currentline, exception)
+ end
+ return res
+end
+
function table_keys_to_lower(table)
- res = {}
- for k, v in pairs(table) do
- res[k:lower()] = v
- end
+ local res = {}
+ for k, v in pairs(table) do
+ res[k:lower()] = v
+ end
return res
end
function contains(table, value)
- for k,v in pairs(table) do
+ for _, v in pairs(table) do
if v == value then
return true
end
end
- return false
+ return false
end