github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/apiserver/facades/controller/crosscontroller/mock_test.go (about) 1 // Copyright 2017 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package crosscontroller_test 5 6 import "gopkg.in/tomb.v2" 7 8 type mockNotifyWatcher struct { 9 tomb tomb.Tomb 10 changes chan struct{} 11 } 12 13 func newMockNotifyWatcher() *mockNotifyWatcher { 14 w := &mockNotifyWatcher{changes: make(chan struct{}, 1)} 15 w.tomb.Go(func() error { 16 <-w.tomb.Dying() 17 return nil 18 }) 19 return w 20 } 21 22 func (w *mockNotifyWatcher) Stop() error { 23 w.Kill() 24 return w.Wait() 25 } 26 27 func (w *mockNotifyWatcher) Wait() error { 28 return w.tomb.Wait() 29 } 30 31 func (w *mockNotifyWatcher) Kill() { 32 w.tomb.Kill(nil) 33 } 34 35 func (w *mockNotifyWatcher) Err() error { 36 return w.tomb.Err() 37 } 38 39 func (w *mockNotifyWatcher) Changes() <-chan struct{} { 40 return w.changes 41 }