Added test for get_imei()
Skyweave Test, Lint, and Deploy Ritual / Test and Lint Code (push) Successful in 28s
Skyweave Test, Lint, and Deploy Ritual / Deploy to Roof Unit (push) Successful in 15s

This commit is contained in:
wes
2025-06-17 15:02:29 -04:00
parent 3773f7edda
commit 5c958f2ae8
+52
View File
@@ -105,6 +105,58 @@ Read result:
end)
describe("Skyweave IMEI Retrieval", function()
before_each(function()
_G.original_execute_command = utils.execute_command
end)
after_each(function()
utils.execute_command = _G.original_execute_command
_G.original_execute_command = nil
end)
it("should correctly parse a valid IMEI from uqmi output", function()
-- 1. Define the simulated output from a successful `uqmi --get-imei` invocation.
local mock_uqmi_output = '"015647000004953"'
-- 2. Mock the command executor to return our simulated data.
utils.execute_command = function(command)
assert.are.equal("uqmi -d /dev/cdc-wdm0 --get-imei", command)
return mock_uqmi_output
end
-- 3. Execute the function under test.
local imei, err = utils.get_modem_imei()
-- 4. Assert the expected outcome.
assert.is_nil(err)
assert.are.equal("015647000004953", imei)
end)
it("should return an error on nil or empty command output", function()
utils.execute_command = function()
return nil
end
local imei, err = utils.get_modem_imei()
assert.is_nil(imei)
assert.are.equal("No output from uqmi --get-imei command", err)
end)
it("should return an error if the IMEI cannot be parsed", function()
local malformed_output = "Couldn't get IMEI: QMI protocol error: 'InvalidHandle'"
utils.execute_command = function()
return malformed_output
end
local imei, err = utils.get_modem_imei()
assert.is_nil(imei)
assert.are.equal("Failed to parse IMEI from uqmi output", err)
end)
end)
-- more 'describe' blocks here to test other functions in utils.lua
end)