Cleaning up some comments, adding unit test for get_iccid()
Skyweave Test, Lint, and Deploy Ritual / Test and Lint Code (push) Failing after 31s
Skyweave Test, Lint, and Deploy Ritual / Deploy to Roof Unit (push) Has been skipped

This commit is contained in:
wes
2025-06-17 13:48:37 -04:00
parent 55d15621c0
commit 5db7a9a864
2 changed files with 67 additions and 8 deletions
+66
View File
@@ -34,6 +34,72 @@ describe("Skyweave Utility Functions Module", function()
end)
describe("Skyweave ICCID Retrieval", function()
-- This block runs before each test ('it' block).
-- It's used to set up our mock environment.
before_each(function()
-- Create a backup of the original command executor.
-- This ensures we do not permanently damage the original scripture.
_G.original_execute_command = utils.execute_command
end)
-- This block runs after each test.
-- It restores the original function, ensuring our tests do not interfere with each other.
after_each(function()
utils.execute_command = _G.original_execute_command
_G.original_execute_command = nil
end)
it("should correctly decode a valid qmicli output", function()
-- 1. Define the simulated raw output from a successful qmicli invocation.
local mock_qmicli_output = "QMI-Client: Synchronous call... \n" ..
"[/dev/cdc-wdm0] UIM transparent read result: \n" ..
"Read result:\n" ..
"\t'89:01:41:03:27:25:30:79:07:87:f9'\n"
-- 2. Mock the command executor to return our simulated data.
utils.execute_command = function(command)
assert.are.equal("qmicli -d /dev/cdc-wdm0 --uim-read-transparent=0x3F00,0x2FE2", command)
return mock_qmicli_output
end
-- 3. Execute the function under test.
local iccid, err = utils.get_sim_iccid()
-- 4. Assert the expected outcome.
assert.is_nil(err)
assert.are.equal("981014307252039770789f", iccid)
end)
it("should return an error on nil or empty command output", function()
-- 1. Mock the command executor to return nil.
utils.execute_command = function(command)
return nil
end
-- 2. Execute and assert.
local iccid, err = utils.get_sim_iccid()
assert.is_nil(iccid)
assert.are.equal("No output from qmicli command", err)
end)
it("should return an error if the raw data cannot be parsed", function()
-- 1. Mock a response that lacks the 'Read result:' scripture.
local malformed_output = "QMI-Client: Call failed: QMI protocol error"
utils.execute_command = function(command)
return malformed_output
end
-- 2. Execute and assert.
local iccid, err = utils.get_sim_iccid()
assert.is_nil(iccid)
assert.are.equal("Failed to parse raw ICCID data from qmicli output", err)
end)
end)
-- more 'describe' blocks here to test other functions in utils.lua
end)