forked from juju/juju
-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker_test.go
63 lines (51 loc) · 1.62 KB
/
worker_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2017 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package caasenvironupgrader_test
import (
"github.com/juju/testing"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"gopkg.in/juju/names.v3"
"gopkg.in/juju/worker.v1/workertest"
"github.com/juju/juju/core/status"
coretesting "github.com/juju/juju/testing"
"github.com/juju/juju/worker/caasenvironupgrader"
)
type WorkerSuite struct {
testing.IsolationSuite
}
var _ = gc.Suite(&WorkerSuite{})
func (*WorkerSuite) TestNewWorkerValidatesConfig(c *gc.C) {
_, err := caasenvironupgrader.NewWorker(caasenvironupgrader.Config{})
c.Assert(err, gc.ErrorMatches, "nil Facade not valid")
}
func (*WorkerSuite) TestNewWorker(c *gc.C) {
mockFacade := mockFacade{}
mockGateUnlocker := mockGateUnlocker{}
w, err := caasenvironupgrader.NewWorker(caasenvironupgrader.Config{
Facade: &mockFacade,
GateUnlocker: &mockGateUnlocker,
ModelTag: coretesting.ModelTag,
})
c.Assert(err, jc.ErrorIsNil)
workertest.CheckKill(c, w)
mockFacade.CheckCalls(c, []testing.StubCall{
{"SetModelStatus", []interface{}{coretesting.ModelTag, status.Available, "", nilData}},
})
mockGateUnlocker.CheckCallNames(c, "Unlock")
}
type mockFacade struct {
testing.Stub
}
var nilData map[string]interface{}
func (f *mockFacade) SetModelStatus(tag names.ModelTag, status status.Status, info string, data map[string]interface{}) error {
f.MethodCall(f, "SetModelStatus", tag, status, info, data)
return f.NextErr()
}
type mockGateUnlocker struct {
testing.Stub
}
func (g *mockGateUnlocker) Unlock() {
g.MethodCall(g, "Unlock")
g.PopNoErr()
}