summaryrefslogtreecommitdiff
path: root/spec/log_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'spec/log_spec.lua')
-rw-r--r--spec/log_spec.lua53
1 files changed, 53 insertions, 0 deletions
diff --git a/spec/log_spec.lua b/spec/log_spec.lua
new file mode 100644
index 0000000..415c72e
--- /dev/null
+++ b/spec/log_spec.lua
@@ -0,0 +1,53 @@
+describe("log module", function()
+ before_each(function()
+ local succ, log= pcall(require,"log")
+ if succ then log.reset() end
+ end)
+ it("should load",function()
+ require("log")
+ end)
+ it("should ingest a log",function()
+ local log = require("log")
+ log.log("test",nil,"blah")
+ end)
+ it("should return ingested logs from levels",function()
+ local log = require("log")
+ local ret = {}
+ log.log("test",nil,"blah")
+ log.of_level("blah",function(msg)
+ table.insert(ret, msg)
+ end)
+ assert(#ret == 1)
+ assert(ret[1].message == "test")
+ end)
+ it("should return ingested logs from tags", function()
+ local log = require("log")
+ local ret = {}
+ log.info("one",{"one"})
+ log.info("two",{"two"})
+ log.info("one two",{"one","two"})
+ log.of_tags({"one"},function(msg)
+ table.insert(ret,msg)
+ end)
+ assert(#ret == 2)
+ assert(ret[1].message == "one")
+ assert(ret[2].message == "one two")
+ end)
+ it("should allow observers to see the message stream", function()
+ local log = require("log")
+ local ret = {}
+ log.observe(function(chunk)
+ if chunk.level == "panic" then
+ table.insert(ret,chunk)
+ end
+ end)
+ log.info("one")
+ log.info("two")
+ assert(#ret == 0)
+ log.panic("three")
+ assert(#ret == 1)
+ log.info("four")
+ assert(#ret == 1)
+ assert(ret[1].message == "three")
+ end)
+end)