Added test for get_imei()
This commit is contained in:
@@ -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)
|
||||
Reference in New Issue
Block a user