示例#1
0
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)
}
示例#2
0
文件: worker_test.go 项目: bac/juju
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")
}
示例#3
0
文件: worker_test.go 项目: bac/juju
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")
}
示例#4
0
文件: worker_test.go 项目: bac/juju
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")
}
示例#5
0
文件: worker_test.go 项目: bac/juju
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")
}
示例#6
0
文件: worker_test.go 项目: bac/juju
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")
}
示例#7
0
文件: worker_test.go 项目: bac/juju
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")
}