func (s *ValidationSuite) TestMissingClock(c *gc.C) {
	manager, err := leadership.NewManager(leadership.ManagerConfig{
		Client: NewClient(nil, nil),
	})
	c.Check(err, gc.ErrorMatches, "missing clock")
	c.Check(manager, gc.IsNil)
}
func (s *ValidationSuite) TestMissingClient(c *gc.C) {
	manager, err := leadership.NewManager(leadership.ManagerConfig{
		Clock: coretesting.NewClock(time.Now()),
	})
	c.Check(err, gc.ErrorMatches, "missing client")
	c.Check(manager, gc.IsNil)
}
func (s *ValidationSuite) TestMissingMaxSleep(c *gc.C) {
	manager, err := leadership.NewManager(leadership.ManagerConfig{
		Client: NewClient(nil, nil),
		Clock:  coretesting.NewClock(time.Now()),
	})
	c.Check(err, gc.ErrorMatches, "non-positive MaxSleep not valid")
	c.Check(err, jc.Satisfies, errors.IsNotValid)
	c.Check(manager, gc.IsNil)
}
func (s *ValidationSuite) TestMissingClock(c *gc.C) {
	manager, err := leadership.NewManager(leadership.ManagerConfig{
		Client:   NewClient(nil, nil),
		MaxSleep: time.Minute,
	})
	c.Check(err, gc.ErrorMatches, "nil Clock not valid")
	c.Check(err, jc.Satisfies, errors.IsNotValid)
	c.Check(manager, gc.IsNil)
}
Exemple #5
0
// RunTest sets up a Manager and a Clock and passes them into the supplied
// test function. The manager will be cleaned up afterwards.
func (fix *Fixture) RunTest(c *gc.C, test func(leadership.ManagerWorker, *testing.Clock)) {
	clock := testing.NewClock(defaultClockStart)
	client := NewClient(fix.leases, fix.expectCalls)
	manager, err := leadership.NewManager(leadership.ManagerConfig{
		Clock:  clock,
		Client: client,
	})
	c.Assert(err, jc.ErrorIsNil)
	defer func() {
		// Dirty tests will probably have stopped the manager anyway, but no
		// sense leaving them around if things aren't exactly as we expect.
		manager.Kill()
		err := manager.Wait()
		if !fix.expectDirty {
			c.Check(err, jc.ErrorIsNil)
		}
	}()
	defer client.Wait(c)
	test(manager, clock)
}