-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcalendar_test.go
52 lines (39 loc) · 1004 Bytes
/
calendar_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
package main
import (
"testing"
"time"
)
func TestCachedCalendarEventsThenCacheIsPopulated(t *testing.T) {
cc := newCachedCalendar(emptyCalendar{}, 5*time.Second)
cc.events()
if cc.cache == nil {
t.Error("cache was not populated")
}
}
func TestCachedCalendarCleanThenCacheIsCleaned(t *testing.T) {
cc := newCachedCalendar(emptyCalendar{}, 5*time.Second)
cc.events()
cc.clean()
if cc.cache != nil {
t.Error("cache was not cleaned")
}
}
func TestCachedCalendarEventsThenTimerIsSet(t *testing.T) {
cc := newCachedCalendar(emptyCalendar{}, 5*time.Second)
cc.events()
if cc.cleanTimer == nil {
t.Error("timer was not set")
}
}
func TestCachedCalendarCleanThenTimerIsRemoved(t *testing.T) {
cc := newCachedCalendar(emptyCalendar{}, 5*time.Second)
cc.events()
cc.clean()
if cc.cleanTimer != nil {
t.Error("timer was not removed")
}
}
type emptyCalendar struct{}
func (c emptyCalendar) events() (calendarEvents, error) {
return calendarEvents([]*calendarEvent{}), nil
}