示例#1
0
func (s *machineRebootSuite) TestWatchForRebootEvent(c *gc.C) {
	reboot.PatchFacadeCall(s, s.reboot, func(facade string, p interface{}, resp interface{}) error {
		return nil
	})
	_, err := s.reboot.WatchForRebootEvent()
	c.Assert(err, jc.ErrorIsNil)
}
示例#2
0
func (s *machineRebootSuite) TestRequestRebootError(c *gc.C) {
	reboot.PatchFacadeCall(s, s.reboot, func(facade string, p interface{}, resp interface{}) error {
		if entities, ok := p.(params.Entities); ok {
			if len(entities.Entities) != 1 {
				return errors.Errorf("Expected 1 machine, got: %d", len(entities.Entities))
			}
			if entities.Entities[0].Tag != s.machine.Tag().String() {
				return errors.Errorf("Expecting machineTag %s, got %s", entities.Entities[0].Tag, s.machine.Tag().String())
			}
		}
		if resp, ok := resp.(*params.ErrorResults); ok {
			resp.Results = []params.ErrorResult{
				{
					Error: &params.Error{
						Message: "Some error.",
						Code:    params.CodeNotAssigned,
					},
				},
			}
		}
		return nil
	})
	err := s.reboot.RequestReboot()
	c.Assert(err.Error(), gc.Equals, "Some error.")
}
示例#3
0
func (s *machineRebootSuite) TestWatchForRebootEventError(c *gc.C) {
	reboot.PatchFacadeCall(s, s.reboot, func(facade string, p interface{}, resp interface{}) error {
		if resp, ok := resp.(*params.NotifyWatchResult); ok {
			resp.Error = &params.Error{
				Message: "Some error.",
				Code:    params.CodeNotAssigned,
			}
		}
		return nil
	})
	_, err := s.reboot.WatchForRebootEvent()
	c.Assert(err.Error(), gc.Equals, "Some error.")
}
示例#4
0
func (s *machineRebootSuite) TestGetRebootActionMultipleResults(c *gc.C) {
	reboot.PatchFacadeCall(s, s.reboot, func(facade string, p interface{}, resp interface{}) error {
		if resp, ok := resp.(*params.RebootActionResults); ok {
			resp.Results = []params.RebootActionResult{
				{Result: params.ShouldDoNothing},
				{Result: params.ShouldDoNothing},
			}
		}
		return nil
	})
	_, err := s.reboot.GetRebootAction()
	c.Assert(err.Error(), gc.Equals, "expected 1 result, got 2")
}
示例#5
0
func (s *machineRebootSuite) TestGetRebootAction(c *gc.C) {
	reboot.PatchFacadeCall(s, s.reboot, func(facade string, p interface{}, resp interface{}) error {
		if resp, ok := resp.(*params.RebootActionResults); ok {
			resp.Results = []params.RebootActionResult{
				{Result: params.ShouldDoNothing},
			}
		}
		return nil
	})
	rAction, err := s.reboot.GetRebootAction()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(rAction, gc.Equals, params.ShouldDoNothing)
}
示例#6
0
func (s *machineRebootSuite) TestClearRebootError(c *gc.C) {
	reboot.PatchFacadeCall(s, s.reboot, func(facade string, p interface{}, resp interface{}) error {
		if resp, ok := resp.(*params.ErrorResults); ok {
			resp.Results = []params.ErrorResult{
				{
					Error: &params.Error{
						Message: "Some error.",
						Code:    params.CodeNotAssigned,
					},
				},
			}
		}
		return nil
	})
	err := s.reboot.ClearReboot()
	c.Assert(err.Error(), gc.Equals, "Some error.")
}
示例#7
0
func (s *machineRebootSuite) TestRequestReboot(c *gc.C) {
	reboot.PatchFacadeCall(s, s.reboot, func(facade string, p interface{}, resp interface{}) error {
		if entities, ok := p.(params.Entities); ok {
			if len(entities.Entities) != 1 {
				return errors.Errorf("Expected 1 machine, got: %d", len(entities.Entities))
			}
			if entities.Entities[0].Tag != s.machine.Tag().String() {
				return errors.Errorf("Expecting machineTag %s, got %s", entities.Entities[0].Tag, s.machine.Tag().String())
			}
		}
		if resp, ok := resp.(*params.ErrorResults); ok {
			resp.Results = []params.ErrorResult{
				{},
			}
		}
		return nil
	})
	err := s.reboot.RequestReboot()
	c.Assert(err, jc.ErrorIsNil)
}