github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/apiserver/testing/fakenotifywatcher.go (about) 1 // Copyright 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package testing 5 6 import ( 7 "launchpad.net/tomb" 8 9 "github.com/juju/juju/state" 10 ) 11 12 // FakeNotifyWatcher is an implementation of state.NotifyWatcher which 13 // is useful in tests. 14 type FakeNotifyWatcher struct { 15 tomb tomb.Tomb 16 C chan struct{} 17 } 18 19 var _ state.NotifyWatcher = (*FakeNotifyWatcher)(nil) 20 21 func NewFakeNotifyWatcher() *FakeNotifyWatcher { 22 return &FakeNotifyWatcher{ 23 C: make(chan struct{}, 1), 24 } 25 } 26 27 func (w *FakeNotifyWatcher) Stop() error { 28 w.Kill() 29 return w.Wait() 30 } 31 32 func (w *FakeNotifyWatcher) Kill() { 33 w.tomb.Kill(nil) 34 w.tomb.Done() 35 } 36 37 func (w *FakeNotifyWatcher) Wait() error { 38 return w.tomb.Wait() 39 } 40 41 func (w *FakeNotifyWatcher) Err() error { 42 return w.tomb.Err() 43 } 44 45 func (w *FakeNotifyWatcher) Changes() <-chan struct{} { 46 return w.C 47 }