forked from juju/description
-
Notifications
You must be signed in to change notification settings - Fork 0
/
charmmanifest_test.go
159 lines (131 loc) · 4.1 KB
/
charmmanifest_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
// 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 CharmManifestSerializationSuite struct {
SerializationSuite
}
var _ = gc.Suite(&CharmManifestSerializationSuite{})
func (s *CharmManifestSerializationSuite) SetUpTest(c *gc.C) {
s.importName = "charmManifest"
s.importFunc = func(m map[string]interface{}) (interface{}, error) {
return importCharmManifest(m)
}
}
func (s *CharmManifestSerializationSuite) TestNewCharmManifest(c *gc.C) {
args := CharmManifestArgs{
Bases: []CharmManifestBase{
charmManifestBase{
Name_: "ubuntu",
Channel_: "22.04",
Architectures_: []string{"amd64"},
},
},
}
metadata := newCharmManifest(args)
c.Assert(metadata.Bases(), gc.DeepEquals, []CharmManifestBase{
charmManifestBase{
Name_: "ubuntu",
Channel_: "22.04",
Architectures_: []string{"amd64"},
},
})
}
func minimalCharmManifestMap() map[interface{}]interface{} {
return map[interface{}]interface{}{
"version": 1,
"bases": []interface{}{},
}
}
func minimalCharmManifestArgs() CharmManifestArgs {
return CharmManifestArgs{}
}
func minimalCharmManifest() *charmManifest {
return newCharmManifest(minimalCharmManifestArgs())
}
func maximalCharmManifestMap() map[interface{}]interface{} {
return map[interface{}]interface{}{
"version": 1,
"bases": []interface{}{
map[interface{}]interface{}{
"name": "ubuntu",
"channel": "22.04",
"architectures": []interface{}{"amd64"},
},
},
}
}
func maximalCharmManifestArgs() CharmManifestArgs {
return CharmManifestArgs{
Bases: []CharmManifestBase{
charmManifestBase{
Name_: "ubuntu",
Channel_: "22.04",
Architectures_: []string{"amd64"},
},
},
}
}
func maximalCharmManifest() *charmManifest {
return newCharmManifest(maximalCharmManifestArgs())
}
func (s *CharmManifestSerializationSuite) TestMinimalMatches(c *gc.C) {
bytes, err := yaml.Marshal(minimalCharmManifest())
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, minimalCharmManifestMap())
}
func (s *CharmManifestSerializationSuite) TestMaximalMatches(c *gc.C) {
bytes, err := yaml.Marshal(maximalCharmManifest())
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, maximalCharmManifestMap())
}
func (s *CharmManifestSerializationSuite) TestMinimalParsingSerializedData(c *gc.C) {
initial := minimalCharmManifest()
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 := importCharmManifest(source)
c.Assert(err, jc.ErrorIsNil)
c.Assert(instance, jc.DeepEquals, initial)
}
func (s *CharmManifestSerializationSuite) TestMaximalParsingSerializedData(c *gc.C) {
initial := maximalCharmManifest()
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 := importCharmManifest(source)
c.Assert(err, jc.ErrorIsNil)
c.Assert(instance, jc.DeepEquals, initial)
}
func (s *CharmManifestSerializationSuite) exportImportVersion(c *gc.C, origin_ *charmManifest, version int) *charmManifest {
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 := importCharmManifest(source)
c.Assert(err, jc.ErrorIsNil)
return origin
}
func (s *CharmManifestSerializationSuite) TestV1ParsingReturnsLatest(c *gc.C) {
args := maximalCharmManifestArgs()
originV1 := newCharmManifest(args)
originLatest := *originV1
originResult := s.exportImportVersion(c, originV1, 1)
c.Assert(*originResult, jc.DeepEquals, originLatest)
}