-
Notifications
You must be signed in to change notification settings - Fork 0
/
topics_test.go
49 lines (35 loc) · 1.05 KB
/
topics_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
var subscribed []string
var unsubscribed []string
func subscribe(topic string) {
subscribed = append(subscribed, topic)
}
func unsubscribe(topic string) {
unsubscribed = append(unsubscribed, topic)
}
func TestSubscribeTopicOnFirstAdd(t *testing.T) {
topics := NewTopics(subscribe, unsubscribe)
topics.UpdateTopics([]string{"foo"})
assert.Equal(t, []string{"foo"}, subscribed)
assert.Empty(t, unsubscribed)
}
func TestDontSubscribeOnAlreadySubscribedTopic(t *testing.T) {
topics := NewTopics(subscribe, unsubscribe)
topics.UpdateTopics([]string{"foo"})
subscribed = []string{}
topics.UpdateTopics([]string{"foo", "bar"})
assert.Equal(t, []string{"bar"}, subscribed)
assert.Empty(t, unsubscribed)
}
func TestCallUnsubribe(t *testing.T) {
topics := NewTopics(subscribe, unsubscribe)
topics.UpdateTopics([]string{"foo"})
subscribed = []string{}
topics.UpdateTopics([]string{"bar"})
assert.Equal(t, []string{"foo"}, unsubscribed)
assert.Equal(t, []string{"bar"}, subscribed)
}