-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmatches_filter_test.go
65 lines (50 loc) · 2 KB
/
matches_filter_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
package main
import (
"testing"
"time"
"github.com/stretchr/testify/suite"
)
type MatchesFilterSuite struct {
suite.Suite
todayMatch Match
yesterdayMatch Match
starredMatch Match
takeEveryMatchStub *TakeEveryMatchFilter
}
func (s *MatchesFilterSuite) SetupTest() {
s.takeEveryMatchStub = &TakeEveryMatchFilter{}
s.todayMatch = NewMatch("first", "second", "/link", 0, time.Now())
s.yesterdayMatch = NewMatch("first", "second", "/link", 0, time.Now().Add(-24*time.Hour))
s.starredMatch = NewMatch("first", "second", "/link", 5, time.Now())
}
func (s MatchesFilterSuite) TestTodayFilterTakeTodayMatches() {
s.True(NewFilterTodayMatches(s.takeEveryMatchStub).TakeMatch(s.todayMatch))
}
func (s MatchesFilterSuite) TestTodayFilterSkipNotTodayMatches() {
s.False(NewFilterTodayMatches(s.takeEveryMatchStub).TakeMatch(s.yesterdayMatch))
}
func (s MatchesFilterSuite) TestStarredFilterSkipUnstarredMatches() {
unstarredMatch := s.todayMatch
s.False(NewStarredFilter(s.takeEveryMatchStub).TakeMatch(unstarredMatch))
}
func (s MatchesFilterSuite) TestStarredFilterTakeAllStarredMatches() {
s.True(NewStarredFilter(s.takeEveryMatchStub).TakeMatch(s.starredMatch))
}
func (s MatchesFilterSuite) TestTeamFilterSkipUknownTeam() {
s.False(NewTeamFilter(s.takeEveryMatchStub, "team").TakeMatch(s.todayMatch))
}
func (s MatchesFilterSuite) TestTeamFilterTakeMatchWithGivenTeam() {
s.True(NewTeamFilter(s.takeEveryMatchStub, "first").TakeMatch(s.todayMatch))
s.True(NewTeamFilter(s.takeEveryMatchStub, "second").TakeMatch(s.todayMatch))
}
func (s MatchesFilterSuite) TestFiltersAlreadySkippedMatches() {
skip := &RejectingFilterStub{}
s.False(NewFilterTodayMatches(skip).TakeMatch(s.todayMatch))
s.False(NewStarredFilter(skip).TakeMatch(s.todayMatch))
s.False(NewTeamFilter(skip, "team").TakeMatch(s.todayMatch))
}
func TestMatchesFilterSuite(t *testing.T) {
suite.Run(t, new(MatchesFilterSuite))
}
type RejectingFilterStub struct{}
func (f *RejectingFilterStub) TakeMatch(m Match) bool { return false }