-
Notifications
You must be signed in to change notification settings - Fork 23
/
charmactions_test.go
171 lines (143 loc) · 4.41 KB
/
charmactions_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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// Copyright 2024 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
package description
import (
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"gopkg.in/yaml.v2"
)
type CharmActionsSerializationSuite struct {
SerializationSuite
}
var _ = gc.Suite(&CharmActionsSerializationSuite{})
func (s *CharmActionsSerializationSuite) SetUpTest(c *gc.C) {
s.importName = "charmActions"
s.importFunc = func(m map[string]interface{}) (interface{}, error) {
return importCharmActions(m)
}
}
func (s *CharmActionsSerializationSuite) TestNewCharmActions(c *gc.C) {
args := CharmActionsArgs{
Actions: map[string]CharmAction{
"echo": charmAction{
Description_: "echo description",
Parallel_: true,
ExecutionGroup_: "group1",
Parameters_: map[string]interface{}{
"message": "string",
},
},
},
}
metadata := newCharmActions(args)
c.Assert(metadata.Actions(), gc.DeepEquals, map[string]CharmAction{
"echo": charmAction{
Description_: "echo description",
Parallel_: true,
ExecutionGroup_: "group1",
Parameters_: map[string]interface{}{
"message": "string",
},
},
})
}
func minimalCharmActionsMap() map[interface{}]interface{} {
return map[interface{}]interface{}{
"version": 1,
"actions": map[interface{}]interface{}{},
}
}
func minimalCharmActionsArgs() CharmActionsArgs {
return CharmActionsArgs{}
}
func minimalCharmActions() *charmActions {
return newCharmActions(minimalCharmActionsArgs())
}
func maximalCharmActionsMap() map[interface{}]interface{} {
return map[interface{}]interface{}{
"version": 1,
"actions": map[interface{}]interface{}{
"echo": map[interface{}]interface{}{
"description": "echo description",
"parallel": true,
"execution-group": "group1",
"parameters": map[interface{}]interface{}{
"message": "string",
},
},
},
}
}
func maximalCharmActionsArgs() CharmActionsArgs {
return CharmActionsArgs{
Actions: map[string]CharmAction{
"echo": charmAction{
Description_: "echo description",
Parallel_: true,
ExecutionGroup_: "group1",
Parameters_: map[string]interface{}{
"message": "string",
},
},
},
}
}
func maximalCharmActions() *charmActions {
return newCharmActions(maximalCharmActionsArgs())
}
func (s *CharmActionsSerializationSuite) TestMinimalMatches(c *gc.C) {
bytes, err := yaml.Marshal(minimalCharmActions())
c.Assert(err, jc.ErrorIsNil)
var source map[interface{}]interface{}
err = yaml.Unmarshal(bytes, &source)
c.Assert(err, jc.ErrorIsNil)
c.Assert(source, jc.DeepEquals, minimalCharmActionsMap())
}
func (s *CharmActionsSerializationSuite) TestMaximalMatches(c *gc.C) {
bytes, err := yaml.Marshal(maximalCharmActions())
c.Assert(err, jc.ErrorIsNil)
var source map[interface{}]interface{}
err = yaml.Unmarshal(bytes, &source)
c.Assert(err, jc.ErrorIsNil)
c.Assert(source, jc.DeepEquals, maximalCharmActionsMap())
}
func (s *CharmActionsSerializationSuite) TestMinimalParsingSerializedData(c *gc.C) {
initial := minimalCharmActions()
bytes, err := yaml.Marshal(initial)
c.Assert(err, jc.ErrorIsNil)
var source map[string]interface{}
err = yaml.Unmarshal(bytes, &source)
c.Assert(err, jc.ErrorIsNil)
instance, err := importCharmActions(source)
c.Assert(err, jc.ErrorIsNil)
c.Assert(instance, jc.DeepEquals, initial)
}
func (s *CharmActionsSerializationSuite) TestMaximalParsingSerializedData(c *gc.C) {
initial := maximalCharmActions()
bytes, err := yaml.Marshal(initial)
c.Assert(err, jc.ErrorIsNil)
var source map[string]interface{}
err = yaml.Unmarshal(bytes, &source)
c.Assert(err, jc.ErrorIsNil)
instance, err := importCharmActions(source)
c.Assert(err, jc.ErrorIsNil)
c.Assert(instance, jc.DeepEquals, initial)
}
func (s *CharmActionsSerializationSuite) exportImportVersion(c *gc.C, origin_ *charmActions, version int) *charmActions {
origin_.Version_ = version
bytes, err := yaml.Marshal(origin_)
c.Assert(err, jc.ErrorIsNil)
var source map[string]interface{}
err = yaml.Unmarshal(bytes, &source)
c.Assert(err, jc.ErrorIsNil)
origin, err := importCharmActions(source)
c.Assert(err, jc.ErrorIsNil)
return origin
}
func (s *CharmActionsSerializationSuite) TestV1ParsingReturnsLatest(c *gc.C) {
args := maximalCharmActionsArgs()
originV1 := newCharmActions(args)
originLatest := *originV1
originResult := s.exportImportVersion(c, originV1, 1)
c.Assert(*originResult, jc.DeepEquals, originLatest)
}