Exemplo n.º 1
0
func (s *MinUnitsSuite) testEnsureMinUnitsBefore(c *gc.C, f func(), minUnits, expectedUnits int) {
	service := s.service
	err := service.SetMinUnits(minUnits)
	c.Assert(err, gc.IsNil)
	defer state.SetBeforeHooks(c, s.State, f).Check()
	err = service.EnsureMinUnits()
	c.Assert(err, gc.IsNil)
	assertAllUnits(c, service, expectedUnits)
}
Exemplo n.º 2
0
func (s *MinUnitsSuite) TestEnsureMinUnitsDestroyServiceBefore(c *gc.C) {
	s.addUnits(c, 1)
	err := s.service.SetMinUnits(42)
	c.Assert(err, gc.IsNil)
	defer state.SetBeforeHooks(c, s.State, func() {
		err := s.service.Destroy()
		c.Assert(err, gc.IsNil)
	}).Check()
	c.Assert(s.service.EnsureMinUnits(), gc.ErrorMatches,
		`cannot ensure minimum units for service "dummy-service": service is not alive`)
}
Exemplo n.º 3
0
func (s *MinUnitsSuite) TestMinUnitsRemoveBefore(c *gc.C) {
	err := s.service.SetMinUnits(41)
	c.Assert(err, gc.IsNil)
	defer state.SetBeforeHooks(c, s.State, func() {
		err := s.service.SetMinUnits(0)
		c.Assert(err, gc.IsNil)
		s.assertRevno(c, 0, mgo.ErrNotFound)
	}).Check()
	err = s.service.SetMinUnits(0)
	c.Assert(err, gc.IsNil)
	c.Assert(s.service.MinUnits(), gc.Equals, 0)
}
Exemplo n.º 4
0
func (s *MinUnitsSuite) testDestroyOrRemoveServiceBefore(c *gc.C, initial, input int, preventRemoval bool) {
	err := s.service.SetMinUnits(initial)
	c.Assert(err, gc.IsNil)
	expectedErr := `cannot set minimum units for service "dummy-service": service "dummy-service" not found`
	if preventRemoval {
		expectedErr = `cannot set minimum units for service "dummy-service": service is no longer alive`
		s.addUnits(c, 1)
	}
	defer state.SetBeforeHooks(c, s.State, func() {
		err := s.service.Destroy()
		c.Assert(err, gc.IsNil)
	}).Check()
	err = s.service.SetMinUnits(input)
	c.Assert(err, gc.ErrorMatches, expectedErr)
	s.assertRevno(c, 0, mgo.ErrNotFound)
}