From 5422b9ac91827da2c48ad5c75d00c7813dd60483 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Mon, 18 May 2026 15:29:14 +0400 Subject: [PATCH] Simplify tests --- tests/test_plum.nim | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/tests/test_plum.nim b/tests/test_plum.nim index d33541e..cbd1d1f 100644 --- a/tests/test_plum.nim +++ b/tests/test_plum.nim @@ -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)