1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
4
package undertaker_test
7
"github.com/juju/testing"
8
jc "github.com/juju/testing/checkers"
11
"github.com/juju/juju/apiserver/params"
12
"github.com/juju/juju/environs"
13
"github.com/juju/juju/status"
14
"github.com/juju/juju/watcher"
15
"github.com/juju/juju/worker"
16
"github.com/juju/juju/worker/undertaker"
17
"github.com/juju/juju/worker/workertest"
20
type mockFacade struct {
22
info params.UndertakerModelInfoResult
25
func (mock *mockFacade) ModelInfo() (params.UndertakerModelInfoResult, error) {
26
mock.stub.AddCall("ModelInfo")
27
if err := mock.stub.NextErr(); err != nil {
28
return params.UndertakerModelInfoResult{}, err
33
func (mock *mockFacade) WatchModelResources() (watcher.NotifyWatcher, error) {
34
mock.stub.AddCall("WatchModelResources")
35
if err := mock.stub.NextErr(); err != nil {
39
changes := make(chan struct{}, count)
40
for i := 0; i < count; i++ {
44
Worker: workertest.NewErrorWorker(nil),
49
func (mock *mockFacade) ProcessDyingModel() error {
50
mock.stub.AddCall("ProcessDyingModel")
51
return mock.stub.NextErr()
54
func (mock *mockFacade) SetStatus(status status.Status, info string, data map[string]interface{}) error {
55
mock.stub.MethodCall(mock, "SetStatus", status, info, data)
56
return mock.stub.NextErr()
59
func (mock *mockFacade) RemoveModel() error {
60
mock.stub.AddCall("RemoveModel")
61
return mock.stub.NextErr()
64
type mockEnviron struct {
69
func (mock *mockEnviron) Destroy() error {
70
mock.stub.AddCall("Destroy")
71
return mock.stub.NextErr()
74
type mockWatcher struct {
79
func (mock *mockWatcher) Changes() watcher.NotifyChannel {
84
info params.UndertakerModelInfoResult
89
func (fix fixture) cleanup(c *gc.C, w worker.Worker) {
91
workertest.DirtyKill(c, w)
93
workertest.CleanKill(c, w)
97
func (fix fixture) run(c *gc.C, test func(worker.Worker)) *testing.Stub {
98
stub := &testing.Stub{}
99
environ := &mockEnviron{
102
facade := &mockFacade{
106
stub.SetErrors(fix.errors...)
107
w, err := undertaker.NewUndertaker(undertaker.Config{
111
c.Assert(err, jc.ErrorIsNil)
112
defer fix.cleanup(c, w)