✅🧱 add tests & ci changes
This commit is contained in:
36
devices-api/spec/db_spec.lua
Normal file
36
devices-api/spec/db_spec.lua
Normal file
@@ -0,0 +1,36 @@
|
||||
describe("db", function()
|
||||
local db
|
||||
|
||||
before_each(function()
|
||||
db = require("db")
|
||||
end)
|
||||
|
||||
describe("config", function()
|
||||
it("has required connection fields", function()
|
||||
assert.is_table(db.config)
|
||||
assert.is_string(db.config.host)
|
||||
assert.is_string(db.config.port)
|
||||
assert.is_string(db.config.database)
|
||||
assert.is_string(db.config.user)
|
||||
assert.is_string(db.config.password)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("with_retry", function()
|
||||
it("returns result when function succeeds immediately", function()
|
||||
local result, err = db.with_retry(function()
|
||||
return "ok"
|
||||
end)
|
||||
assert.are.equal("ok", result)
|
||||
assert.is_nil(err)
|
||||
end)
|
||||
|
||||
it("returns nil, err when function fails with non-retryable error", function()
|
||||
local result, err = db.with_retry(function()
|
||||
return nil, "validation failed"
|
||||
end)
|
||||
assert.is_nil(result)
|
||||
assert.are.equal("validation failed", err)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
19
devices-api/spec/log_spec.lua
Normal file
19
devices-api/spec/log_spec.lua
Normal file
@@ -0,0 +1,19 @@
|
||||
describe("log", function()
|
||||
local log
|
||||
|
||||
before_each(function()
|
||||
log = require("log")
|
||||
end)
|
||||
|
||||
it("exposes info, warn, error functions", function()
|
||||
assert.is_function(log.info)
|
||||
assert.is_function(log.warn)
|
||||
assert.is_function(log.error)
|
||||
end)
|
||||
|
||||
it("calls info without error", function()
|
||||
assert.has_no.errors(function()
|
||||
log.info("test message", { component = "test" })
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
Reference in New Issue
Block a user