From ed1dd154b6d3637e6727257943bce6d59583150c Mon Sep 17 00:00:00 2001 From: vyzo Date: Wed, 28 Feb 2018 22:26:42 +0200 Subject: [PATCH] add test for UnregisterTopicValidator --- floodsub_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/floodsub_test.go b/floodsub_test.go index bf5ac80..54c7d96 100644 --- a/floodsub_test.go +++ b/floodsub_test.go @@ -341,6 +341,31 @@ func TestOneToOne(t *testing.T) { checkMessageRouting(t, "foobar", psubs, []*Subscription{sub}) } +func TestRegisterUnregisterValidator(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + hosts := getNetHosts(t, ctx, 1) + psubs := getPubsubs(ctx, hosts) + + err := psubs[0].RegisterTopicValidator("foo", func(context.Context, *Message) bool { + return true + }) + if err != nil { + t.Fatal(err) + } + + err = psubs[0].UnregisterTopicValidator("foo") + if err != nil { + t.Fatal(err) + } + + err = psubs[0].UnregisterTopicValidator("foo") + if err == nil { + t.Fatal("Unregistered bogus topic validator") + } +} + func TestValidate(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel()