func checkInvalid(c *gc.C, config lifeflag.Config, message string) { check := func(err error) { c.Check(err, jc.Satisfies, errors.IsNotValid) c.Check(err, gc.ErrorMatches, message) } err := config.Validate() check(err) worker, err := lifeflag.New(config) c.Check(worker, gc.IsNil) check(err) }
func (*WorkerSuite) TestCreateRandomError(c *gc.C) { stub := &testing.Stub{} stub.SetErrors(errors.New("boom splat")) config := lifeflag.Config{ Facade: newMockFacade(stub), Entity: testEntity, Result: explode, } worker, err := lifeflag.New(config) c.Check(worker, gc.IsNil) c.Check(err, gc.ErrorMatches, "boom splat") checkCalls(c, stub, "Life") }
func (*WorkerSuite) TestCreateNotFoundError(c *gc.C) { stub := &testing.Stub{} stub.SetErrors(apilifeflag.ErrNotFound) config := lifeflag.Config{ Facade: newMockFacade(stub), Entity: testEntity, Result: explode, } worker, err := lifeflag.New(config) c.Check(worker, gc.IsNil) c.Check(err, gc.Equals, lifeflag.ErrNotFound) checkCalls(c, stub, "Life") }
func (*WorkerSuite) TestResultNoRealChange(c *gc.C) { stub := &testing.Stub{} config := lifeflag.Config{ Facade: newMockFacade(stub, life.Alive, life.Alive, life.Dying), Entity: testEntity, Result: life.IsNotDead, } worker, err := lifeflag.New(config) c.Check(err, jc.ErrorIsNil) c.Check(worker.Check(), jc.IsTrue) workertest.CheckAlive(c, worker) workertest.CleanKill(c, worker) checkCalls(c, stub, "Life", "Watch", "Life", "Life") }
func (*WorkerSuite) TestResultSubsequentRealChange(c *gc.C) { stub := &testing.Stub{} config := lifeflag.Config{ Facade: newMockFacade(stub, life.Dying, life.Dying, life.Dead), Entity: testEntity, Result: life.IsNotDead, } worker, err := lifeflag.New(config) c.Check(err, jc.ErrorIsNil) c.Check(worker.Check(), jc.IsTrue) err = workertest.CheckKilled(c, worker) c.Check(err, gc.Equals, lifeflag.ErrValueChanged) checkCalls(c, stub, "Life", "Watch", "Life", "Life") }
func (*WorkerSuite) TestLifeNotFoundError(c *gc.C) { stub := &testing.Stub{} stub.SetErrors(nil, nil, apilifeflag.ErrNotFound) config := lifeflag.Config{ Facade: newMockFacade(stub, life.Alive), Entity: testEntity, Result: never, } worker, err := lifeflag.New(config) c.Check(err, jc.ErrorIsNil) c.Check(worker.Check(), jc.IsFalse) err = workertest.CheckKilled(c, worker) c.Check(err, gc.Equals, lifeflag.ErrNotFound) checkCalls(c, stub, "Life", "Watch", "Life") }
func (*WorkerSuite) TestWatchRandomError(c *gc.C) { stub := &testing.Stub{} stub.SetErrors(nil, errors.New("pew pew")) config := lifeflag.Config{ Facade: newMockFacade(stub, life.Alive), Entity: testEntity, Result: never, } worker, err := lifeflag.New(config) c.Check(err, jc.ErrorIsNil) c.Check(worker.Check(), jc.IsFalse) err = workertest.CheckKilled(c, worker) c.Check(err, gc.ErrorMatches, "pew pew") checkCalls(c, stub, "Life", "Watch") }