-
Notifications
You must be signed in to change notification settings - Fork 0
/
infowriter_test.go
316 lines (300 loc) · 8.48 KB
/
infowriter_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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
// Copyright 2020 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package charmhub
import (
"bytes"
"github.com/juju/charm/v8"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
)
type printInfoSuite struct{}
var _ = gc.Suite(&printInfoSuite{})
func (s *printInfoSuite) TestCharmPrintInfo(c *gc.C) {
ir := getCharmInfoResponse()
ctx := commandContextForTest(c)
iw := makeInfoWriter(ctx.Stdout, ctx.Warningf, false, &ir)
err := iw.Print()
c.Assert(err, jc.ErrorIsNil)
obtained := ctx.Stdout.(*bytes.Buffer).String()
expected := `name: wordpress
charm-id: charmCHARMcharmCHARMcharmCHARM01
summary: WordPress is a full featured web blogging tool, this charm deploys it.
publisher: Wordress Charmers
supports: bionic, xenial
tags: app, seven
subordinate: true
description: |-
This will install and setup WordPress optimized to run in the cloud.
By default it will place Ngnix and php-fpm configured to scale horizontally with
Nginx's reverse proxy.
relations:
provides:
one: two
three: four
requires:
five: six
channels: |
latest/stable: 1.0.3 2019-12-16 (16) 12MB
latest/candidate: 1.0.3 2019-12-16 (17) 12MB
latest/beta: 1.0.3 2019-12-16 (17) 12MB
latest/edge: 1.0.3 2019-12-16 (18) 12MB
`
c.Assert(obtained, gc.Equals, expected)
}
func (s *printInfoSuite) TestCharmPrintInfoWithConfig(c *gc.C) {
ir := getCharmInfoResponse()
ctx := commandContextForTest(c)
iw := makeInfoWriter(ctx.Stdout, ctx.Warningf, true, &ir)
err := iw.Print()
c.Assert(err, jc.ErrorIsNil)
obtained := ctx.Stdout.(*bytes.Buffer).String()
expected := `name: wordpress
charm-id: charmCHARMcharmCHARMcharmCHARM01
summary: WordPress is a full featured web blogging tool, this charm deploys it.
publisher: Wordress Charmers
supports: bionic, xenial
tags: app, seven
subordinate: true
description: |-
This will install and setup WordPress optimized to run in the cloud.
By default it will place Ngnix and php-fpm configured to scale horizontally with
Nginx's reverse proxy.
relations:
provides:
one: two
three: four
requires:
five: six
channels: |
latest/stable: 1.0.3 2019-12-16 (16) 12MB
latest/candidate: 1.0.3 2019-12-16 (17) 12MB
latest/beta: 1.0.3 2019-12-16 (17) 12MB
latest/edge: 1.0.3 2019-12-16 (18) 12MB
config:
settings:
status:
type: string
description: temporary string for unit status
default: hello
thing:
type: string
description: A thing used by the charm.
default: "\U0001F381"
`
c.Assert(obtained, gc.Equals, expected)
}
func (s *printInfoSuite) TestBundleChannelClosed(c *gc.C) {
ir := getBundleInfoClosedTrack()
ctx := commandContextForTest(c)
iw := makeInfoWriter(ctx.Stdout, ctx.Warningf, false, &ir)
err := iw.Print()
c.Assert(err, jc.ErrorIsNil)
obtained := ctx.Stdout.(*bytes.Buffer).String()
expected := `name: osm
channels: |
latest/stable: 1.0.3 2019-12-16 (15) 12MB
latest/candidate: 1.0.3 2019-12-16 (16) 12MB
latest/beta: 1.0.3 2019-12-16 (17) 12MB
latest/edge: 1.0.3 2019-12-16 (18) 12MB
2.8/stable: --
2.8/candidate: 1.0.3 2019-12-13 (56) 12MB
2.8/beta: ^
2.8/edge: 1.0.3 2019-12-17 (60) 12MB
`
c.Assert(obtained, gc.Equals, expected)
}
func (s *printInfoSuite) TestBundlePrintInfo(c *gc.C) {
ir := getBundleInfoResponse()
ctx := commandContextForTest(c)
iw := makeInfoWriter(ctx.Stdout, ctx.Warningf, false, &ir)
err := iw.Print()
c.Assert(err, jc.ErrorIsNil)
obtained := ctx.Stdout.(*bytes.Buffer).String()
expected := `name: osm
bundle-id: bundleBUNDLEbundleBUNDLEbundle01
summary: A bundle by charmed-osm.
publisher: charmed-osm
tags: networking
description: Single instance OSM bundle.
channels: |
latest/stable: 1.0.3 2019-12-16 (16) 12MB
latest/candidate: 1.0.3 2019-12-16 (17) 12MB
latest/beta: 1.0.3 2019-12-16 (17) 12MB
latest/edge: 1.0.3 2019-12-16 (18) 12MB
`
c.Assert(obtained, gc.Equals, expected)
}
func getBundleInfoResponse() InfoResponse {
return InfoResponse{
Type: "Bundle",
ID: "bundleBUNDLEbundleBUNDLEbundle01",
Name: "osm",
Description: "Single instance OSM bundle.",
Publisher: "charmed-osm",
Summary: "A bundle by charmed-osm.",
Tags: []string{"networking"},
Bundle: nil,
Channels: map[string]Channel{
"latest/stable": {
ReleasedAt: "2019-12-16T19:44:44.076943+00:00",
Track: "latest",
Risk: "stable",
Revision: 16,
Size: 12042240,
Version: "1.0.3",
},
"latest/beta": {
ReleasedAt: "2019-12-16T19:44:44.076943+00:00",
Track: "latest",
Risk: "beta",
Revision: 17,
Size: 12042240,
Version: "1.0.3",
},
"latest/candidate": {
ReleasedAt: "2019-12-16T19:44:44.076943+00:00",
Track: "latest",
Risk: "candidate",
Revision: 17,
Size: 12042240,
Version: "1.0.3",
},
"latest/edge": {
ReleasedAt: "2019-12-16T19:44:44.076943+00:00",
Track: "latest",
Risk: "edge",
Revision: 18,
Size: 12042240,
Version: "1.0.3",
}},
Tracks: []string{"latest"},
}
}
func getCharmInfoResponse() InfoResponse {
return InfoResponse{
Type: "charm",
ID: "charmCHARMcharmCHARMcharmCHARM01",
Name: "wordpress",
Summary: "WordPress is a full featured web blogging tool, this charm deploys it.",
Publisher: "Wordress Charmers",
Description: "This will install and setup WordPress optimized to run in the cloud.\nBy default it will place Ngnix and php-fpm configured to scale horizontally with\nNginx's reverse proxy.",
Series: []string{"bionic", "xenial"},
Tags: []string{"app", "seven"},
Charm: &Charm{
Config: &charm.Config{
Options: map[string]charm.Option{
"status": {
Type: "string",
Description: "temporary string for unit status",
Default: "hello",
},
"thing": {
Type: "string",
Description: "A thing used by the charm.",
Default: "🎁",
},
},
},
Subordinate: true,
Relations: map[string]map[string]string{
"provides": {
"one": "two",
"three": "four",
},
"requires": {
"five": "six",
},
},
},
Channels: map[string]Channel{
"latest/stable": {
ReleasedAt: "2019-12-16T19:44:44.076943+00:00",
Track: "latest",
Risk: "stable",
Revision: 16,
Size: 12042240,
Version: "1.0.3",
},
"latest/beta": {
ReleasedAt: "2019-12-16T19:44:44.076943+00:00",
Track: "latest",
Risk: "beta",
Revision: 17,
Size: 12042240,
Version: "1.0.3",
},
"latest/candidate": {
ReleasedAt: "2019-12-16T19:44:44.076943+00:00",
Track: "latest",
Risk: "candidate",
Revision: 17,
Size: 12042240,
Version: "1.0.3",
},
"latest/edge": {
ReleasedAt: "2019-12-16T19:44:44.076943+00:00",
Track: "latest",
Risk: "edge",
Revision: 18,
Size: 12042240,
Version: "1.0.3",
}},
Tracks: []string{"latest"},
}
}
func getBundleInfoClosedTrack() InfoResponse {
return InfoResponse{
Name: "osm",
Type: "bundle",
Channels: map[string]Channel{
"latest/stable": {
ReleasedAt: "2019-12-16T19:44:44.076943+00:00",
Track: "latest",
Risk: "stable",
Revision: 15,
Size: 12042240,
Version: "1.0.3",
},
"latest/beta": {
ReleasedAt: "2019-12-16T19:44:44.076943+00:00",
Track: "latest",
Risk: "beta",
Revision: 17,
Size: 12042240,
Version: "1.0.3",
},
"latest/candidate": {
ReleasedAt: "2019-12-16T19:44:44.076943+00:00",
Track: "latest",
Risk: "candidate",
Revision: 16,
Size: 12042240,
Version: "1.0.3",
},
"latest/edge": {
ReleasedAt: "2019-12-16T19:44:44.076943+00:00",
Track: "latest",
Risk: "edge",
Revision: 18,
Size: 12042240,
Version: "1.0.3",
},
"2.8/candidate": {
ReleasedAt: "2019-12-13T19:44:44.076943+00:00",
Track: "2.8",
Risk: "candidate",
Revision: 56,
Size: 12042240,
Version: "1.0.3",
},
"2.8/edge": {
ReleasedAt: "2019-12-17T19:44:44.076943+00:00",
Track: "2.8",
Risk: "edge",
Revision: 60,
Size: 12042240,
Version: "1.0.3",
}},
Tracks: []string{"latest", "2.8"},
}
}