diff options
Diffstat (limited to 'plugins/broadcast/websockets/conn_context_test.go')
-rw-r--r-- | plugins/broadcast/websockets/conn_context_test.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/plugins/broadcast/websockets/conn_context_test.go b/plugins/broadcast/websockets/conn_context_test.go new file mode 100644 index 00000000..466aaa30 --- /dev/null +++ b/plugins/broadcast/websockets/conn_context_test.go @@ -0,0 +1,28 @@ +package websockets + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestConnContext_ManageTopics(t *testing.T) { + ctx := &ConnContext{Topics: make([]string, 0)} + + assert.Equal(t, []string{}, ctx.Topics) + + ctx.addTopics("a", "b") + assert.Equal(t, []string{"a", "b"}, ctx.Topics) + + ctx.addTopics("a", "c") + assert.Equal(t, []string{"a", "b", "c"}, ctx.Topics) + + ctx.dropTopic("b", "c") + assert.Equal(t, []string{"a"}, ctx.Topics) + + ctx.dropTopic("b", "c") + assert.Equal(t, []string{"a"}, ctx.Topics) + + ctx.dropTopic("a") + assert.Equal(t, []string{}, ctx.Topics) +} |