-
Notifications
You must be signed in to change notification settings - Fork 2
/
events_test.go
66 lines (50 loc) · 1.92 KB
/
events_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
package subscribe
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
var testFile3 = filepath.Join(os.TempDir(), "this_is_a_testfile_for_subtscribe_test3.go.json")
func TestNew(t *testing.T) {
t.Parallel()
assert := assert.New(t)
sub, err := GetDB(testFile3)
assert.NotNil(sub.Events.Names(), "the events slice must not be nil")
assert.Nil(err, "getting a db must produce no error")
assert.EqualValues(0, len(sub.Events.Names()), "event count must be 0 since none have been added")
assert.Nil(sub.Events.New("event_test", nil))
assert.EqualValues(1, len(sub.Events.Names()), "event count must be 1 since 1 was added")
}
func TestGetEvent(t *testing.T) {
t.Parallel()
assert := assert.New(t)
sub, err := GetDB("")
assert.NotNil(sub.Events.Names(), "the events map must not be nil")
assert.Nil(err, "getting a db must produce no error")
assert.Nil(sub.Events.New("event_test", nil))
assert.True(sub.Events.Exists("event_test"), "this event exists so the method must return true")
assert.EqualValues(1, len(sub.Events.Names()), "event count must be 1 since 1 was added")
assert.False(sub.Events.Exists("missing_event"), "this event does not exists")
}
func TestNewEvent(t *testing.T) {
t.Parallel()
a := assert.New(t)
sub := &Subscribe{Events: &Events{Map: make(map[string]*Rules)}}
a.Nil(sub.Events.New("event_test", nil))
a.NotNil(sub.Events.Map["event_test"], "the event rules map must not be nil")
}
func TestRemoveEvent(t *testing.T) {
t.Parallel()
assert := assert.New(t)
sub := &Subscribe{Events: &Events{Map: make(map[string]*Rules)}}
sub.Events.Remove("no_event")
// Make two events to remove.
sub.Events.Map["some_event"] = nil
sub.Events.Map["some_event2"] = nil
// Subscribe a user to one of them.
s := sub.CreateSub("test_contact", "api", true, false) // XXX: count them?
assert.Nil(s.Subscribe("some_event2"))
sub.EventRemove("some_event2")
sub.EventRemove("some_event")
}