github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/state/watcher/helpers_test.go (about) 1 // Copyright 2012, 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package watcher_test 5 6 import ( 7 stderrors "errors" 8 9 gc "gopkg.in/check.v1" 10 "gopkg.in/tomb.v1" 11 12 "github.com/juju/juju/state/watcher" 13 ) 14 15 type dummyWatcher struct { 16 err error 17 } 18 19 func (w *dummyWatcher) Stop() error { 20 return w.err 21 } 22 23 func (w *dummyWatcher) Err() error { 24 return w.err 25 } 26 27 func (s *FastPeriodSuite) TestStop(c *gc.C) { 28 t := &tomb.Tomb{} 29 watcher.Stop(&dummyWatcher{nil}, t) 30 c.Assert(t.Err(), gc.Equals, tomb.ErrStillAlive) 31 32 watcher.Stop(&dummyWatcher{stderrors.New("BLAM")}, t) 33 c.Assert(t.Err(), gc.ErrorMatches, "BLAM") 34 } 35 36 func (s *FastPeriodSuite) TestEnsureErr(c *gc.C) { 37 err := watcher.EnsureErr(&dummyWatcher{stderrors.New("POW")}) 38 c.Assert(err, gc.ErrorMatches, "POW") 39 40 err = watcher.EnsureErr(&dummyWatcher{tomb.ErrStillAlive}) 41 c.Assert(err, gc.ErrorMatches, "expected .* to be stopped: tomb: still alive") 42 43 err = watcher.EnsureErr(&dummyWatcher{nil}) 44 c.Assert(err, gc.ErrorMatches, "expected an error from .*, got nil") 45 }