--- /dev/null
+dofile('./test_utils.lua') -- load test utilities
+
+-- test fixtures
+
+-- count warning message, fail with other than allowed message
+warn_msg = {}
+overriding_msg="[ ta ] warning: overriding previously set trust anchors for ."
+warn_msg[overriding_msg] = 0
+function warn(fmt, ...)
+ msg = string.format(fmt, ...)
+ if warn_msg[msg] == nil then
+ fail("Not allowed warn message: %s", msg)
+ else
+ warn_msg[msg] = warn_msg[msg] + 1
+ end
+end
+
+-- test
+if pcall(trust_anchors.add_file, 'nonwriteable/root.keys', false) then
+ fail("Managed trsut anchor file in directory without write access should fail")
+end
+
+if pcall(trust_anchors.add_file, 'nonexist.keys', true) then
+ fail("Nonexist unmanaged file should fail")
+end
+
+trust_anchors.add_file('root2.keys', true)
+
+trust_anchors.add_file('root1.keys', true)
+if warn_msg[overriding_msg] ~= 1 then
+ fail("Missing warning message for override: %s", overriding_msg)
+end
+
+if trust_anchors.keysets['\0'][1].key_tag ~= 19036 then
+ fail("Not loaded or loaded trust anchor from root1.keys")
+end
+
+-- run test after processed config file
+ev = event.after(0, function (ev)
+ -- check overiding trust anchor from cmdline args
+ if trust_anchors.keysets['\0'][1].key_tag ~= 20326 then
+ fail("Not loaded or loaded trust anchor from root2.keys")
+ end
+ if warn_msg[overriding_msg] ~= 2 then
+ fail("Missing warning message for override: %s", overriding_msg)
+ end
+ quit()
+end)