2021-06-18 10:30:24 +00:00
|
|
|
{.used.}
|
|
|
|
|
|
|
|
import
|
|
|
|
testutils/unittests,
|
|
|
|
chronos,
|
|
|
|
stew/results,
|
|
|
|
../../waku/v2/utils/namespacing
|
|
|
|
|
|
|
|
procSuite "Namespacing utils":
|
|
|
|
|
|
|
|
asyncTest "Create from string":
|
|
|
|
# Expected case
|
|
|
|
let ns = NamespacedTopic.fromString("/waku/2/default-waku/proto").tryGet()
|
|
|
|
|
|
|
|
check:
|
|
|
|
ns.application == "waku"
|
|
|
|
ns.version == "2"
|
|
|
|
ns.topicName == "default-waku"
|
|
|
|
ns.encoding == "proto"
|
|
|
|
|
|
|
|
# Invalid cases
|
2021-07-16 15:13:36 +00:00
|
|
|
expect CatchableError:
|
2021-06-18 10:30:24 +00:00
|
|
|
# Topic should be namespaced
|
|
|
|
discard NamespacedTopic.fromString("this-is-not-namespaced").tryGet()
|
|
|
|
|
2021-07-16 15:13:36 +00:00
|
|
|
expect CatchableError:
|
2021-06-18 10:30:24 +00:00
|
|
|
# Topic should start with '/'
|
|
|
|
discard NamespacedTopic.fromString("waku/2/default-waku/proto").tryGet()
|
|
|
|
|
2021-07-16 15:13:36 +00:00
|
|
|
expect CatchableError:
|
2021-06-18 10:30:24 +00:00
|
|
|
# Topic has too few parts
|
|
|
|
discard NamespacedTopic.fromString("/waku/2/default-waku").tryGet()
|
|
|
|
|
2021-07-16 15:13:36 +00:00
|
|
|
expect CatchableError:
|
2021-06-18 10:30:24 +00:00
|
|
|
# Topic has too many parts
|
|
|
|
discard NamespacedTopic.fromString("/waku/2/default-waku/proto/2").tryGet()
|
|
|
|
|
|
|
|
asyncTest "Stringify namespaced topic":
|
|
|
|
var ns = NamespacedTopic()
|
|
|
|
|
|
|
|
ns.application = "waku"
|
|
|
|
ns.version = "2"
|
|
|
|
ns.topicName = "default-waku"
|
|
|
|
ns.encoding = "proto"
|
|
|
|
|
|
|
|
check:
|
|
|
|
$ns == "/waku/2/default-waku/proto"
|