-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
news_test.go
72 lines (52 loc) · 1.81 KB
/
news_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
package news_test
import (
"testing"
"github.com/tj/assert"
"github.com/tj/go-news"
)
// newStorage helper.
func newStorage(t testing.TB) *news.Store {
return news.New("news_test")
}
// Test adding subscribers.
func TestStore_AddSubscriber(t *testing.T) {
db := newStorage(t)
err := db.AddSubscriber("general", "manny@apex.sh")
assert.NoError(t, err, "adding subscriber")
err = db.AddSubscriber("general", "tobi@apex.sh")
assert.NoError(t, err, "adding subscriber")
err = db.AddSubscriber("general", "loki@apex.sh")
assert.NoError(t, err, "adding subscriber")
err = db.AddSubscriber("general", "jane@apex.sh")
assert.NoError(t, err, "adding subscriber")
err = db.AddSubscriber("blog", "tj@apex.sh")
assert.NoError(t, err, "adding subscriber")
err = db.AddSubscriber("blog", "jane@apex.sh")
assert.NoError(t, err, "adding subscriber")
}
// Test removing subscribers.
func TestStore_RemoveSubscriber(t *testing.T) {
db := newStorage(t)
err := db.AddSubscriber("up", "luna@apex.sh")
assert.NoError(t, err, "adding subscriber")
emails, err := db.GetSubscribers("up")
assert.NoError(t, err, "listing subscribers")
assert.Len(t, emails, 1, "emails")
err = db.RemoveSubscriber("up", "luna@apex.sh")
assert.NoError(t, err, "removing subscriber")
emails, err = db.GetSubscribers("up")
assert.NoError(t, err, "listing subscribers")
assert.Len(t, emails, 0, "emails")
err = db.RemoveSubscriber("up", "luna@apex.sh")
assert.NoError(t, err, "removing subscriber")
}
// Test listing subscribers.
func TestStore_GetSubscribers(t *testing.T) {
db := newStorage(t)
emails, err := db.GetSubscribers("general")
assert.NoError(t, err, "listing subscribers")
assert.Len(t, emails, 4, "emails")
emails, err = db.GetSubscribers("blog")
assert.NoError(t, err, "listing subscribers")
assert.Len(t, emails, 2, "emails")
}