Exemple #1
0
func (s *FlagSuite) TestClaimError(c *gc.C) {
	var stub testing.Stub
	stub.SetErrors(errors.New("squish"))

	worker, err := singular.NewFlagWorker(singular.FlagConfig{
		Facade:   newStubFacade(&stub),
		Clock:    &fakeClock{},
		Duration: time.Hour,
	})
	c.Check(worker, gc.IsNil)
	c.Check(err, gc.ErrorMatches, "squish")
}
Exemple #2
0
func (s *InterfaceSuite) TestRequestRebootNow(c *gc.C) {
	ctx := s.GetContext(c, -1, "").(*context.HookContext)

	var stub testing.Stub
	var p *mockProcess
	p = &mockProcess{func() error {
		// Reboot priority should be set before the process
		// is killed, or else the client waiting for the
		// process to exit will race with the setting of
		// the priority.
		priority := ctx.GetRebootPriority()
		c.Assert(priority, gc.Equals, jujuc.RebootNow)
		return stub.NextErr()
	}}
	stub.SetErrors(errors.New("process is already dead"))
	ctx.SetProcess(p)

	err := ctx.RequestReboot(jujuc.RebootNow)
	c.Assert(err, jc.ErrorIsNil)

	// Everything went well, so priority should still be RebootNow.
	priority := ctx.GetRebootPriority()
	c.Assert(priority, gc.Equals, jujuc.RebootNow)
}
Exemple #3
0
func (s *ContextFactorySuite) testLeadershipContextWiring(c *gc.C, createContext func() runner.Context) {
	var stub testing.Stub
	stub.SetErrors(errors.New("bam"))
	restore := runner.PatchNewLeadershipContext(
		func(accessor runner.LeadershipSettingsAccessor, tracker leadership.Tracker) runner.LeadershipContext {
			stub.AddCall("NewLeadershipContext", accessor, tracker)
			return &StubLeadershipContext{Stub: &stub}
		},
	)
	defer restore()

	ctx := createContext()
	isLeader, err := ctx.IsLeader()
	c.Check(err, gc.ErrorMatches, "bam")
	c.Check(isLeader, jc.IsFalse)

	stub.CheckCalls(c, []testing.StubCall{{
		FuncName: "NewLeadershipContext",
		Args:     []interface{}{s.uniter.LeadershipSettings, fakeTracker{}},
	}, {
		FuncName: "IsLeader",
	}})

}