-
Notifications
You must be signed in to change notification settings - Fork 23
/
provisioningstate_test.go
119 lines (97 loc) · 3.16 KB
/
provisioningstate_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
// Copyright 2023 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 ProvisioningStateSerializationSuite struct {
SerializationSuite
}
var _ = gc.Suite(&ProvisioningStateSerializationSuite{})
func (s *ProvisioningStateSerializationSuite) SetUpTest(c *gc.C) {
s.importName = "provisioning-state"
s.importFunc = func(m map[string]interface{}) (interface{}, error) {
return importProvisioningState(m)
}
}
func (s *ProvisioningStateSerializationSuite) TestNewProvisioningState(c *gc.C) {
args := ProvisioningStateArgs{
Scaling: true,
ScaleTarget: 10,
}
instance := newProvisioningState(&args)
c.Assert(instance.Scaling(), jc.IsTrue)
c.Assert(instance.ScaleTarget(), gc.Equals, 10)
}
func minimalProvisioningStateMap() map[interface{}]interface{} {
return map[interface{}]interface{}{
"version": 1,
"scaling": true,
"scale-target": 10,
}
}
func minimalProvisioningStateArgs() *ProvisioningStateArgs {
return &ProvisioningStateArgs{
Scaling: true,
ScaleTarget: 10,
}
}
func minimalProvisioningState() *provisioningState {
return newProvisioningState(minimalProvisioningStateArgs())
}
func maximalProvisioningStateMap() map[interface{}]interface{} {
return map[interface{}]interface{}{
"version": 1,
"scaling": true,
"scale-target": 10,
}
}
func maximalProvisioningStateArgs() *ProvisioningStateArgs {
return &ProvisioningStateArgs{
Scaling: true,
ScaleTarget: 10,
}
}
func maximalProvisioningState() *provisioningState {
return newProvisioningState(maximalProvisioningStateArgs())
}
func (s *ProvisioningStateSerializationSuite) TestMinimalMatches(c *gc.C) {
bytes, err := yaml.Marshal(minimalProvisioningState())
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, minimalProvisioningStateMap())
}
func (s *ProvisioningStateSerializationSuite) TestMaximalMatches(c *gc.C) {
bytes, err := yaml.Marshal(maximalProvisioningState())
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, maximalProvisioningStateMap())
}
func (s *ProvisioningStateSerializationSuite) TestParsingSerializedData(c *gc.C) {
initial := maximalProvisioningState()
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 := importProvisioningState(source)
c.Assert(err, jc.ErrorIsNil)
c.Assert(instance, jc.DeepEquals, initial)
}
func (s *ProvisioningStateSerializationSuite) exportImportVersion(c *gc.C, origin_ *provisioningState, version int) *provisioningState {
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 := importProvisioningState(source)
c.Assert(err, jc.ErrorIsNil)
return origin
}