-
Notifications
You must be signed in to change notification settings - Fork 0
/
heart_test.go
44 lines (32 loc) · 996 Bytes
/
heart_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
package tsuki_test
import (
"testing"
"time"
"github.com/kureduro/tsuki"
)
func TestHeart(t *testing.T) {
spyPoller := &tsuki.SpyPoller{}
spySleeper := &tsuki.SpySleeper{}
heart := &tsuki.Heart{
Poller: spyPoller,
Sleeper: spySleeper,
}
const tickCount = 10
heart.Poll(tickCount)
if spyPoller.CallCount != tickCount {
t.Errorf("got %d polls, want %d", spyPoller.CallCount, tickCount)
}
if spySleeper.CallCount != tickCount {
t.Errorf("got %d calls to sleep, want %d", spySleeper.CallCount, tickCount)
}
}
func TestConfigurableSleeper(t *testing.T) {
spySleeperTime := &tsuki.SpySleeperTime{}
sleepFor := 3 * time.Second
sleeper := &tsuki.ConfigurableSleeper{sleepFor, spySleeperTime.Sleep}
sleeper.Sleep()
if spySleeperTime.DurationSlept != sleepFor {
t.Errorf("slept for %v, but expected to sleep %v", spySleeperTime.DurationSlept, sleepFor)
}
}
// TODO: tests for HTTPPoller