예제 #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))
}