This repository has been archived by the owner on Apr 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cleaner_test.go
130 lines (114 loc) · 2.67 KB
/
cleaner_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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package main
import (
"io"
"log"
"net/url"
"os"
"testing"
"time"
"github.com/ChimeraCoder/anaconda"
"github.com/matryer/is"
)
func TestMain(m *testing.M) {
log.SetOutput(io.Discard)
os.Exit(m.Run())
}
func TestCleaner(t *testing.T) {
is := is.New(t)
tweetCreatedAt := time.Now()
createdAtFormatted := tweetCreatedAt.Format(time.RubyDate)
twitterAPIMock := &TwitterAPIMock{
GetSelfFunc: func(v url.Values) (anaconda.User, error) {
return anaconda.User{Id: 1}, nil
},
UnRetweetFunc: func(id int64, trimUser bool) (anaconda.Tweet, error) {
return anaconda.Tweet{}, nil
},
UnfavoriteFunc: func(id int64) (anaconda.Tweet, error) {
return anaconda.Tweet{}, nil
},
DeleteTweetFunc: func(id int64, trimUser bool) (anaconda.Tweet, error) {
return anaconda.Tweet{}, nil
},
}
twitterAPIMock.GetUserTimelineFunc = func(v url.Values) ([]anaconda.Tweet, error) {
if len(twitterAPIMock.GetUserTimelineCalls()) == 2 {
return []anaconda.Tweet{
{
Id: 123,
CreatedAt: createdAtFormatted,
Favorited: true,
}}, nil
}
return []anaconda.Tweet{
{
Id: 123,
CreatedAt: createdAtFormatted,
Favorited: true,
},
{
Id: 1234,
CreatedAt: createdAtFormatted,
Retweeted: true,
},
{
Id: 1234,
CreatedAt: createdAtFormatted,
Retweeted: true,
Favorited: true,
},
{
Id: 1,
User: anaconda.User{Id: 1},
CreatedAt: createdAtFormatted,
Favorited: true,
},
{
Id: 1,
User: anaconda.User{Id: 1},
CreatedAt: createdAtFormatted,
Retweeted: true,
},
{
Id: 1,
CreatedAt: createdAtFormatted,
},
}, nil
}
twitterAPIMock.GetFavoritesFunc = func(v url.Values) ([]anaconda.Tweet, error) {
if len(twitterAPIMock.GetFavoritesCalls()) == 2 {
return []anaconda.Tweet{
{
Id: 123,
CreatedAt: createdAtFormatted,
Favorited: true,
}}, nil
}
return []anaconda.Tweet{
{
Id: 123,
CreatedAt: createdAtFormatted,
Favorited: true,
},
{
Id: 1,
User: anaconda.User{Id: 1},
CreatedAt: createdAtFormatted,
Favorited: true,
},
}, nil
}
c := NewCleaner(&Twitter{twitterAPIMock}, time.Second*1, time.Second*1, false)
c.Init()
go func() {
is.NoErr(c.Start())
}()
time.Sleep(time.Millisecond * 1100)
c.Stop()
is.Equal(1, len(twitterAPIMock.GetSelfCalls()))
is.Equal(2, len(twitterAPIMock.GetUserTimelineCalls()))
is.Equal(2, len(twitterAPIMock.GetFavoritesCalls()))
is.Equal(5, len(twitterAPIMock.UnfavoriteCalls()))
is.Equal(3, len(twitterAPIMock.UnRetweetCalls()))
is.Equal(2, len(twitterAPIMock.DeleteTweetCalls()))
}