2021-06-18 10:30:24 +00:00
|
|
|
{.used.}
|
|
|
|
|
|
|
|
import
|
|
|
|
stew/results,
|
2023-02-10 08:54:47 +00:00
|
|
|
testutils/unittests
|
|
|
|
import
|
2021-06-18 10:30:24 +00:00
|
|
|
../../waku/v2/utils/namespacing
|
|
|
|
|
2023-02-10 08:54:47 +00:00
|
|
|
suite "Namespacing utils":
|
2021-06-18 10:30:24 +00:00
|
|
|
|
2023-02-10 08:54:47 +00:00
|
|
|
test "Create from string":
|
2021-06-18 10:30:24 +00:00
|
|
|
# Expected case
|
2023-02-10 08:54:47 +00:00
|
|
|
let nsRes = NamespacedTopic.fromString("/waku/2/default-waku/proto")
|
|
|
|
|
|
|
|
require nsRes.isOk()
|
|
|
|
|
|
|
|
let ns = nsRes.get()
|
|
|
|
|
2021-06-18 10:30:24 +00:00
|
|
|
check:
|
|
|
|
ns.application == "waku"
|
|
|
|
ns.version == "2"
|
|
|
|
ns.topicName == "default-waku"
|
|
|
|
ns.encoding == "proto"
|
2023-02-10 08:54:47 +00:00
|
|
|
|
|
|
|
test "Invalid string - Topic is not namespaced":
|
|
|
|
check NamespacedTopic.fromString("this-is-not-namespaced").isErr()
|
|
|
|
|
|
|
|
test "Invalid string - Topic should start with slash":
|
|
|
|
check NamespacedTopic.fromString("waku/2/default-waku/proto").isErr()
|
|
|
|
|
|
|
|
test "Invalid string - Topic has too few parts":
|
|
|
|
check NamespacedTopic.fromString("/waku/2/default-waku").isErr()
|
|
|
|
|
|
|
|
test "Invalid string - Topic has too many parts":
|
|
|
|
check NamespacedTopic.fromString("/waku/2/default-waku/proto/2").isErr()
|
|
|
|
|
|
|
|
test "Stringify namespaced topic":
|
2021-06-18 10:30:24 +00:00
|
|
|
var ns = NamespacedTopic()
|
|
|
|
|
|
|
|
ns.application = "waku"
|
|
|
|
ns.version = "2"
|
|
|
|
ns.topicName = "default-waku"
|
|
|
|
ns.encoding = "proto"
|
2023-02-10 08:54:47 +00:00
|
|
|
|
2021-06-18 10:30:24 +00:00
|
|
|
check:
|
|
|
|
$ns == "/waku/2/default-waku/proto"
|