-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.go
98 lines (81 loc) · 1.94 KB
/
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
config "pubsubroller/config"
"pubsubroller/subscription"
"pubsubroller/topic"
"time"
)
// mock structures for testing
type fakeSubscriptionCallbacks struct {
IsInitialized bool
IsFinazlied bool
Calls int
}
func (f *fakeSubscriptionCallbacks) Initialized() {
f.IsInitialized = true
}
func (f *fakeSubscriptionCallbacks) Each(_ subscription.Subscription) {
f.Calls++
}
func (f *fakeSubscriptionCallbacks) Finalized(counter countable) {
f.IsFinazlied = true
}
type fakeTopicCallbacks struct {
IsInitialized bool
IsFinazlied bool
Calls int
}
func (f *fakeTopicCallbacks) Initialized() {
f.IsInitialized = true
}
func (f *fakeTopicCallbacks) Each(_ topic.Topic) {
f.Calls++
}
func (f *fakeTopicCallbacks) Finalized(counter countable) {
f.IsFinazlied = true
}
// all operations have 1s sleep in order to test whether goroutine is working
type fakeClient struct{}
func (_ fakeClient) CreateSubscription(_ subscription.Subscription) error {
time.Sleep(1 * time.Second)
return nil
}
func (_ fakeClient) DeleteSubscription(_ subscription.Subscription) error {
time.Sleep(1 * time.Second)
return nil
}
func (_ fakeClient) CreateTopic(_ topic.Topic) error {
time.Sleep(1 * time.Second)
return nil
}
func (_ fakeClient) DeleteTopic(_ topic.Topic) error {
time.Sleep(1 * time.Second)
return nil
}
var (
mockConfig = config.Configuration{
Internal_Topics_: map[string]config.Topic{
"topic1": {
Internal_Subscriptions_: []config.Subscription{
{Name: "subscription11"},
{Name: "subscription12"},
{Name: "subscription13"},
},
},
"topic2": {
Internal_Subscriptions_: []config.Subscription{
{Name: "subscription21"},
{Name: "subscription22"},
{Name: "subscription23"},
},
},
"topic3": {
Internal_Subscriptions_: []config.Subscription{
{Name: "subscription31"},
{Name: "subscription32"},
{Name: "subscription33"},
},
},
},
}
)