mirror of
https://github.com/logos-storage/nim-libplum.git
synced 2026-06-07 01:29:27 +00:00
Simplify tests
This commit is contained in:
parent
2bb7e99c8b
commit
5422b9ac91
@ -36,31 +36,15 @@ suite "plum":
|
||||
check not hasMapping(999)
|
||||
|
||||
const miniupnp_protocol {.strdefine.} = ""
|
||||
# The flag is passed by the Docker / Podman container
|
||||
when miniupnp_protocol == "natpmp":
|
||||
# miniupnpd is compiled without PCP: PCP probes time out and libplum must
|
||||
# fall back to NAT-PMP on its own.
|
||||
suite "plum - natpmp fallback (PCP timeout)":
|
||||
test "createMapping TCP via NAT-PMP fallback":
|
||||
let logLevel = if getEnv("LIBPLUM_VERBOSE") == "1": PLUM_LOG_LEVEL_VERBOSE
|
||||
else: PLUM_LOG_LEVEL_NONE
|
||||
check init(discoverTimeout = 15000, logLevel = logLevel).isOk()
|
||||
# The flag is passed by the Docker / Podman container.
|
||||
# natpmp: miniupnpd compiled without PCP — PCP probes time out and libplum
|
||||
# must fall back to NAT-PMP on its own (tests the silent-timeout fallback fix).
|
||||
when miniupnp_protocol != "":
|
||||
const expectedMappingProtocol =
|
||||
when miniupnp_protocol == "pcp": PCP
|
||||
elif miniupnp_protocol == "natpmp": NatPmp
|
||||
else: UPnP
|
||||
|
||||
let r = waitFor createMapping(TCP, 8101, timeout = seconds(40))
|
||||
check r.isOk()
|
||||
if r.isOk():
|
||||
let res = r.value
|
||||
check res.mapping.externalPort > 0
|
||||
check res.mapping.externalHost.len > 0
|
||||
check res.mapping.mappingProtocol == NatPmp
|
||||
check hasMapping(res.id)
|
||||
if getEnv("TEST_VERBOSE") == "1":
|
||||
echo "NAT-PMP TCP: " & res.mapping.externalHost & ":" & $res.mapping.externalPort
|
||||
destroyMapping(res.id)
|
||||
|
||||
discard cleanup()
|
||||
|
||||
elif miniupnp_protocol != "":
|
||||
suite "plum - " & miniupnp_protocol & " using miniupnp":
|
||||
test "createMapping TCP and destroyMapping":
|
||||
let logLevel = if getEnv("LIBPLUM_VERBOSE") == "1": PLUM_LOG_LEVEL_VERBOSE
|
||||
@ -73,7 +57,7 @@ elif miniupnp_protocol != "":
|
||||
let res = r.value
|
||||
check res.mapping.externalPort > 0
|
||||
check res.mapping.externalHost.len > 0
|
||||
check res.mapping.mappingProtocol == (if miniupnp_protocol == "pcp": PCP else: UPnP)
|
||||
check res.mapping.mappingProtocol == expectedMappingProtocol
|
||||
check hasMapping(res.id)
|
||||
if getEnv("TEST_VERBOSE") == "1":
|
||||
echo miniupnp_protocol & " TCP: " & res.mapping.externalHost & ":" & $res.mapping.externalPort
|
||||
@ -91,7 +75,7 @@ elif miniupnp_protocol != "":
|
||||
if r.isOk():
|
||||
let res = r.value
|
||||
check res.mapping.externalPort > 0
|
||||
check res.mapping.mappingProtocol == (if miniupnp_protocol == "pcp": PCP else: UPnP)
|
||||
check res.mapping.mappingProtocol == expectedMappingProtocol
|
||||
if getEnv("TEST_VERBOSE") == "1":
|
||||
echo miniupnp_protocol & " UDP: " & res.mapping.externalHost & ":" & $res.mapping.externalPort
|
||||
destroyMapping(res.id)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user