1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
9
jc "github.com/juju/testing/checkers"
10
gc "gopkg.in/check.v1"
12
"github.com/juju/juju/testing"
13
"github.com/juju/juju/watcher"
16
func NewNotifyWatcherC(c *gc.C, watcher watcher.NotifyWatcher, preAssert func()) NotifyWatcherC {
20
return NotifyWatcherC{
27
type NotifyWatcherC struct {
29
Watcher watcher.NotifyWatcher
33
// AssertOneChange fails if no change is sent before a long time has passed; or
34
// if, subsequent to that, any further change is sent before a short time has
36
func (c NotifyWatcherC) AssertOneChange() {
39
case _, ok := <-c.Watcher.Changes():
40
c.Assert(ok, jc.IsTrue)
41
case <-time.After(testing.LongWait):
42
c.Fatalf("watcher did not send change")
47
// AssertNoChange fails if it manages to read a value from Changes before a
48
// short time has passed.
49
func (c NotifyWatcherC) AssertNoChange() {
52
case _, ok := <-c.Watcher.Changes():
53
c.Fatalf("watcher sent unexpected change: (_, %v)", ok)
54
case <-time.After(testing.ShortWait):
58
// AssertStops Kills the watcher and asserts (1) that Wait completes without
59
// error before a long time has passed; and (2) that Changes remains open but
60
// no values are being sent.
61
func (c NotifyWatcherC) AssertStops() {
63
wait := make(chan error)
66
wait <- c.Watcher.Wait()
69
case <-time.After(testing.LongWait):
70
c.Fatalf("watcher never stopped")
72
c.Assert(err, jc.ErrorIsNil)
77
case _, ok := <-c.Watcher.Changes():
78
c.Fatalf("watcher sent unexpected change: (_, %v)", ok)