-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsidecar_watcher_test.go
More file actions
64 lines (50 loc) · 1.57 KB
/
sidecar_watcher_test.go
File metadata and controls
64 lines (50 loc) · 1.57 KB
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
package main
import (
"errors"
"testing"
"time"
"github.com/relistan/go-director"
log "github.com/sirupsen/logrus"
. "github.com/smartystreets/goconvey/convey"
)
func Test_NewSidecarWatcher(t *testing.T) {
Convey("NewSidecarWatcher properly configured a SidecarWatcher", t, func() {
log.SetLevel(log.ErrorLevel)
looper := director.NewFreeLooper(1, make(chan error))
notifyChan := make(chan struct{})
watcher := NewSidecarWatcher("http://example.com/watch", looper, notifyChan)
So(watcher.looper, ShouldEqual, looper)
So(watcher.notifyChan, ShouldEqual, notifyChan)
So(watcher.timer, ShouldNotBeNil)
So(watcher.RefreshConn, ShouldEqual, CONNECTION_REFRESH_TIME)
})
}
func Test_onChange(t *testing.T) {
Convey("onChange()", t, func() {
log.SetLevel(log.ErrorLevel)
looper := director.NewFreeLooper(1, make(chan error))
notifyChan := make(chan struct{}, 1)
watcher := NewSidecarWatcher("http://example.com/watch", looper, notifyChan)
Convey("returns nil on error", func() {
err := errors.New("Oh no!")
watcher.onChange(nil, err)
So(len(notifyChan), ShouldEqual, 0)
})
Convey("notifies the channel", func() {
watcher.onChange(nil, nil)
So(len(notifyChan), ShouldEqual, 1)
})
Convey("resets the Timer", func() {
watcher.RefreshConn = time.Duration(0)
watcher.onChange(nil, nil)
// We know it was reset if it expires right away because it's
// reset to the value of RefreshConn instead of the default.
var expired bool
select {
case <-watcher.timer.C:
expired = true
}
So(expired, ShouldBeTrue)
})
})
}