TEST - cover IMEI collision retries

This commit is contained in:
Eichenholz
2026-08-04 18:37:26 +02:00
parent a8a4076896
commit 9613a7ad1b
3 changed files with 39 additions and 11 deletions
+16
View File
@@ -7,4 +7,20 @@ assert(SkyPhoneImei.IsValid(imei), "generated IMEI must pass its check digit")
assert(not SkyPhoneImei.IsValid(imei:sub(1, 14) .. tostring((tonumber(imei:sub(15, 15)) + 1) % 10)), "invalid check digit must fail")
assert(not SkyPhoneImei.IsValid("123"), "short IMEI must fail")
local entropy = {
"550e8400-e29b-41d4-a716-446655440000",
"6ba7b810-9dad-11d1-80b4-00c04fd430c8",
}
local entropy_index = 0
local reserve_attempts = 0
local reserved = SkyPhoneImei.Reserve(function()
entropy_index = entropy_index + 1
return entropy[entropy_index]
end, function()
reserve_attempts = reserve_attempts + 1
return reserve_attempts == 2
end)
assert(reserve_attempts == 2, "IMEI reservation must retry database collisions")
assert(reserved == SkyPhoneImei.FromEntropy(entropy[2]), "IMEI reservation must return the accepted candidate")
print("IMEI tests passed")