Add basic tcp socket test

This commit is contained in:
2025-06-27 03:29:29 +10:00
parent 4f548bf9e9
commit 0c4639c3e9
2 changed files with 22 additions and 1 deletions

17
crates/lb/tests/net.lua Normal file
View File

@@ -0,0 +1,17 @@
local ok, net = pcall(require, "lb:net")
if not ok then return end
describe("tcp", function()
describe("socket", function()
test("bind", function()
local socket = net:bind_tcp("127.0.0.1")
-- binds to the correct port
assert(tostring(socket:local_addr():ip()) == "127.0.0.1")
assert(socket:local_addr():port() ~= 0)
-- should not be able to rebind socket
assert(not pcall(socket.bind, socket, net:socketaddr("127.0.0.1")))
end)
end)
end)