-
Notifications
You must be signed in to change notification settings - Fork 0
/
watcher_internal_test.go
113 lines (100 loc) · 3.39 KB
/
watcher_internal_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Copyright 2020 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package apiserver
import (
"github.com/golang/mock/gomock"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"github.com/juju/juju/apiserver/mocks"
"github.com/juju/juju/core/life"
"github.com/juju/juju/core/multiwatcher"
"github.com/juju/juju/core/status"
"github.com/juju/juju/rpc/params"
"github.com/juju/juju/testing"
)
type allWatcherSuite struct {
testing.BaseSuite
}
var _ = gc.Suite(&allWatcherSuite{})
func (s *allWatcherSuite) TestTranslateApplicationWithStatus(c *gc.C) {
s.assertTranslateApplicationWithStatus(c, newAllWatcherDeltaTranslater())
}
func (s *allWatcherSuite) assertTranslateApplicationWithStatus(c *gc.C, t DeltaTranslater) {
input := &multiwatcher.ApplicationInfo{
ModelUUID: testing.ModelTag.Id(),
Name: "test-app",
CharmURL: "test-app",
Life: life.Alive,
Status: multiwatcher.StatusInfo{
Current: status.Active,
},
}
output := t.TranslateApplication(input)
c.Assert(output, jc.DeepEquals, ¶ms.ApplicationInfo{
ModelUUID: input.ModelUUID,
Name: input.Name,
CharmURL: input.CharmURL,
Life: input.Life,
Status: params.StatusInfo{
Current: status.Active,
},
})
}
func (s *allWatcherSuite) TestTranslateAction(c *gc.C) {
t := newAllWatcherDeltaTranslater()
input := &multiwatcher.ActionInfo{
ModelUUID: testing.ModelTag.Id(),
ID: "2",
Parameters: map[string]interface{}{"foo": "bar"},
Results: map[string]interface{}{"done": true},
}
output := t.TranslateAction(input)
c.Assert(output, jc.DeepEquals, ¶ms.ActionInfo{
ModelUUID: input.ModelUUID,
Id: input.ID,
Receiver: input.Receiver,
Name: input.Name,
Status: input.Status,
Message: input.Message,
Enqueued: input.Enqueued,
Started: input.Started,
Completed: input.Completed,
})
}
func newDelta(info multiwatcher.EntityInfo) multiwatcher.Delta {
return multiwatcher.Delta{Entity: info}
}
func (s *allWatcherSuite) TestTranslate(c *gc.C) {
ctrl := gomock.NewController(c)
defer ctrl.Finish()
dt := mocks.NewMockDeltaTranslater(ctrl)
gomock.InOrder(
dt.EXPECT().TranslateModel(gomock.Any()).Return(nil),
dt.EXPECT().TranslateApplication(gomock.Any()).Return(nil),
dt.EXPECT().TranslateRemoteApplication(gomock.Any()).Return(nil),
dt.EXPECT().TranslateMachine(gomock.Any()).Return(nil),
dt.EXPECT().TranslateUnit(gomock.Any()).Return(nil),
dt.EXPECT().TranslateCharm(gomock.Any()).Return(nil),
dt.EXPECT().TranslateRelation(gomock.Any()).Return(nil),
dt.EXPECT().TranslateBranch(gomock.Any()).Return(nil),
dt.EXPECT().TranslateAnnotation(gomock.Any()).Return(nil),
dt.EXPECT().TranslateBlock(gomock.Any()).Return(nil),
dt.EXPECT().TranslateAction(gomock.Any()).Return(nil),
dt.EXPECT().TranslateApplicationOffer(gomock.Any()).Return(nil),
)
deltas := []multiwatcher.Delta{
newDelta(&multiwatcher.ModelInfo{}),
newDelta(&multiwatcher.ApplicationInfo{}),
newDelta(&multiwatcher.RemoteApplicationUpdate{}),
newDelta(&multiwatcher.MachineInfo{}),
newDelta(&multiwatcher.UnitInfo{}),
newDelta(&multiwatcher.CharmInfo{}),
newDelta(&multiwatcher.RelationInfo{}),
newDelta(&multiwatcher.BranchInfo{}),
newDelta(&multiwatcher.AnnotationInfo{}),
newDelta(&multiwatcher.BlockInfo{}),
newDelta(&multiwatcher.ActionInfo{}),
newDelta(&multiwatcher.ApplicationOfferInfo{}),
}
_ = translate(dt, deltas)
}