コード例 #1
0
ファイル: worker_test.go プロジェクト: bac/juju
func (*WorkerSuite) TestWatchErrorNonEmptyRunningActions(c *gc.C) {
	stub := &testing.Stub{}
	stub.SetErrors(nil, errors.New("ignored"), errors.New("kuso"))
	facade := &mockFacade{
		stub:           stub,
		runningActions: fakeRunningActions,
	}
	config := machineactions.WorkerConfig{
		Facade:       facade,
		MachineTag:   fakeTag,
		HandleAction: mockHandleAction(stub),
	}
	worker, err := machineactions.NewMachineActionsWorker(config)
	c.Assert(err, jc.ErrorIsNil)
	err = workertest.CheckKilled(c, worker)
	c.Check(err, gc.ErrorMatches, "kuso")

	stub.CheckCalls(c, []testing.StubCall{{
		FuncName: "RunningActions",
		Args:     []interface{}{fakeTag},
	}, {
		FuncName: "ActionFinish",
		Args:     []interface{}{thirdActionTag, params.ActionFailed, "action cancelled"},
	}, {
		FuncName: "WatchActionNotifications",
		Args:     []interface{}{fakeTag},
	}})
}
コード例 #2
0
ファイル: worker_test.go プロジェクト: bac/juju
func (*WorkerSuite) TestInvalidFacade(c *gc.C) {
	worker, err := machineactions.NewMachineActionsWorker(machineactions.WorkerConfig{
		Facade: nil,
	})
	c.Assert(err, gc.ErrorMatches, "nil Facade not valid")
	c.Assert(err, jc.Satisfies, errors.IsNotValid)
	c.Assert(worker, gc.IsNil)
}
コード例 #3
0
ファイル: worker_test.go プロジェクト: bac/juju
func (*WorkerSuite) TestInvalidMachineTag(c *gc.C) {
	worker, err := machineactions.NewMachineActionsWorker(machineactions.WorkerConfig{
		Facade:     &mockFacade{},
		MachineTag: names.MachineTag{},
	})
	c.Assert(err, gc.ErrorMatches, "unspecified MachineTag not valid")
	c.Assert(err, jc.Satisfies, errors.IsNotValid)
	c.Assert(worker, gc.IsNil)
}
コード例 #4
0
ファイル: worker_test.go プロジェクト: bac/juju
func (*WorkerSuite) TestWorkerNoErr(c *gc.C) {
	stub := &testing.Stub{}
	worker, err := machineactions.NewMachineActionsWorker(defaultConfig(stub))
	c.Assert(err, jc.ErrorIsNil)

	workertest.CheckAlive(c, worker)
	workertest.CleanKill(c, worker)
	stub.CheckCalls(c, getSuccessfulCalls(allCalls))
}
コード例 #5
0
ファイル: worker_test.go プロジェクト: bac/juju
func (*WorkerSuite) TestRunningActionsError(c *gc.C) {
	stub := &testing.Stub{}
	stub.SetErrors(errors.New("splash"))
	worker, err := machineactions.NewMachineActionsWorker(defaultConfig(stub))
	c.Assert(err, jc.ErrorIsNil)
	err = workertest.CheckKilled(c, worker)
	c.Check(err, gc.ErrorMatches, "splash")

	stub.CheckCalls(c, getSuccessfulCalls(1))
}
コード例 #6
0
ファイル: worker_test.go プロジェクト: bac/juju
func (*WorkerSuite) TestInvalidHandleAction(c *gc.C) {
	worker, err := machineactions.NewMachineActionsWorker(machineactions.WorkerConfig{
		Facade:       &mockFacade{},
		MachineTag:   fakeTag,
		HandleAction: nil,
	})
	c.Assert(err, gc.ErrorMatches, "nil HandleAction not valid")
	c.Assert(err, jc.Satisfies, errors.IsNotValid)
	c.Assert(worker, gc.IsNil)
}
コード例 #7
0
ファイル: worker_test.go プロジェクト: bac/juju
func (*WorkerSuite) TestCannotBeginAction(c *gc.C) {
	stub := &testing.Stub{}
	stub.SetErrors(nil, nil, nil, errors.New("kermack"))
	worker, err := machineactions.NewMachineActionsWorker(defaultConfig(stub))
	c.Assert(err, jc.ErrorIsNil)
	err = workertest.CheckKilled(c, worker)
	c.Check(errors.Cause(err), gc.ErrorMatches, "kermack")

	stub.CheckCalls(c, getSuccessfulCalls(4))
}
コード例 #8
0
ファイル: worker_test.go プロジェクト: bac/juju
func (*WorkerSuite) TestFailHandlingSecondActionSendAllResults(c *gc.C) {
	stub := &testing.Stub{}
	stub.SetErrors(nil, nil, nil, nil, nil, nil, nil, nil, errors.New("kryptonite"))
	worker, err := machineactions.NewMachineActionsWorker(defaultConfig(stub))
	c.Assert(err, jc.ErrorIsNil)
	workertest.CheckAlive(c, worker)
	workertest.CleanKill(c, worker)

	successfulCalls := getSuccessfulCalls(allCalls)
	successfulCalls[9].Args = []interface{}{secondActionTag, params.ActionFailed, "kryptonite"}
	stub.CheckCalls(c, successfulCalls)
}
コード例 #9
0
ファイル: worker_test.go プロジェクト: bac/juju
func (*WorkerSuite) TestFirstActionHandleErrButFinishErrCannotRetrieveSecond(c *gc.C) {
	stub := &testing.Stub{}
	stub.SetErrors(nil, nil, nil, nil, errors.New("sentToActionFinish"), nil, errors.New("gotcha"))
	worker, err := machineactions.NewMachineActionsWorker(defaultConfig(stub))
	c.Assert(err, jc.ErrorIsNil)
	err = workertest.CheckKilled(c, worker)
	c.Check(errors.Cause(err), gc.ErrorMatches, "gotcha")

	successfulCalls := getSuccessfulCalls(7)
	successfulCalls[5].Args = []interface{}{firstActionTag, params.ActionFailed, "sentToActionFinish"}
	stub.CheckCalls(c, successfulCalls)
}
コード例 #10
0
ファイル: worker_test.go プロジェクト: bac/juju
func (*WorkerSuite) TestInvalidActionId(c *gc.C) {
	stub := &testing.Stub{}
	facade := &mockFacade{
		stub: stub,
		watcherSendInvalidValues: true,
	}
	config := machineactions.WorkerConfig{
		Facade:       facade,
		MachineTag:   fakeTag,
		HandleAction: mockHandleAction(stub),
	}
	worker, err := machineactions.NewMachineActionsWorker(config)
	c.Assert(err, jc.ErrorIsNil)
	err = workertest.CheckKilled(c, worker)
	c.Check(err, gc.ErrorMatches, "got invalid action id invalid-action-id")

	stub.CheckCalls(c, getSuccessfulCalls(allCalls))
}