34
34
type MetaSuite struct{}
36
var _ = Suite(&MetaSuite{})
36
var _ = gc.Suite(&MetaSuite{})
38
func (s *MetaSuite) TestReadMetaVersion1(c *C) {
38
func (s *MetaSuite) TestReadMetaVersion1(c *gc.C) {
39
39
meta, err := charm.ReadMeta(repoMeta("dummy"))
41
c.Assert(meta.Name, Equals, "dummy")
42
c.Assert(meta.Summary, Equals, "That's a dummy charm.")
43
c.Assert(meta.Description, Equals,
40
c.Assert(err, gc.IsNil)
41
c.Assert(meta.Name, gc.Equals, "dummy")
42
c.Assert(meta.Summary, gc.Equals, "That's a dummy charm.")
43
c.Assert(meta.Description, gc.Equals,
44
44
"This is a longer description which\npotentially contains multiple lines.\n")
45
c.Assert(meta.Format, Equals, 1)
46
c.Assert(meta.OldRevision, Equals, 0)
47
c.Assert(meta.Subordinate, Equals, false)
45
c.Assert(meta.Format, gc.Equals, 1)
46
c.Assert(meta.OldRevision, gc.Equals, 0)
47
c.Assert(meta.Subordinate, gc.Equals, false)
50
func (s *MetaSuite) TestReadMetaVersion2(c *C) {
50
func (s *MetaSuite) TestReadMetaVersion2(c *gc.C) {
51
51
meta, err := charm.ReadMeta(repoMeta("format2"))
53
c.Assert(meta.Name, Equals, "format2")
54
c.Assert(meta.Format, Equals, 2)
55
c.Assert(meta.Categories, HasLen, 0)
52
c.Assert(err, gc.IsNil)
53
c.Assert(meta.Name, gc.Equals, "format2")
54
c.Assert(meta.Format, gc.Equals, 2)
55
c.Assert(meta.Categories, gc.HasLen, 0)
58
func (s *MetaSuite) TestReadCategory(c *C) {
58
func (s *MetaSuite) TestReadCategory(c *gc.C) {
59
59
meta, err := charm.ReadMeta(repoMeta("category"))
61
c.Assert(meta.Categories, DeepEquals, []string{"database"})
60
c.Assert(err, gc.IsNil)
61
c.Assert(meta.Categories, gc.DeepEquals, []string{"database"})
64
func (s *MetaSuite) TestSubordinate(c *C) {
64
func (s *MetaSuite) TestSubordinate(c *gc.C) {
65
65
meta, err := charm.ReadMeta(repoMeta("logging"))
67
c.Assert(meta.Subordinate, Equals, true)
66
c.Assert(err, gc.IsNil)
67
c.Assert(meta.Subordinate, gc.Equals, true)
70
func (s *MetaSuite) TestSubordinateWithoutContainerRelation(c *C) {
70
func (s *MetaSuite) TestSubordinateWithoutContainerRelation(c *gc.C) {
71
71
r := repoMeta("dummy")
72
72
hackYaml := ReadYaml(r)
73
73
hackYaml["subordinate"] = true
74
74
_, err := charm.ReadMeta(hackYaml.Reader())
75
c.Assert(err, ErrorMatches, "subordinate charm \"dummy\" lacks \"requires\" relation with container scope")
75
c.Assert(err, gc.ErrorMatches, "subordinate charm \"dummy\" lacks \"requires\" relation with container scope")
78
func (s *MetaSuite) TestScopeConstraint(c *C) {
78
func (s *MetaSuite) TestScopeConstraint(c *gc.C) {
79
79
meta, err := charm.ReadMeta(repoMeta("logging"))
81
c.Assert(meta.Provides["logging-client"].Scope, Equals, charm.ScopeGlobal)
82
c.Assert(meta.Requires["logging-directory"].Scope, Equals, charm.ScopeContainer)
83
c.Assert(meta.Subordinate, Equals, true)
80
c.Assert(err, gc.IsNil)
81
c.Assert(meta.Provides["logging-client"].Scope, gc.Equals, charm.ScopeGlobal)
82
c.Assert(meta.Requires["logging-directory"].Scope, gc.Equals, charm.ScopeContainer)
83
c.Assert(meta.Subordinate, gc.Equals, true)
86
func (s *MetaSuite) TestParseMetaRelations(c *C) {
86
func (s *MetaSuite) TestParseMetaRelations(c *gc.C) {
87
87
meta, err := charm.ReadMeta(repoMeta("mysql"))
89
c.Assert(meta.Provides["server"], Equals, charm.Relation{
88
c.Assert(err, gc.IsNil)
89
c.Assert(meta.Provides["server"], gc.Equals, charm.Relation{
91
91
Role: charm.RoleProvider,
92
92
Interface: "mysql",
93
93
Scope: charm.ScopeGlobal,
95
c.Assert(meta.Requires, IsNil)
96
c.Assert(meta.Peers, IsNil)
95
c.Assert(meta.Requires, gc.IsNil)
96
c.Assert(meta.Peers, gc.IsNil)
98
98
meta, err = charm.ReadMeta(repoMeta("riak"))
100
c.Assert(meta.Provides["endpoint"], Equals, charm.Relation{
99
c.Assert(err, gc.IsNil)
100
c.Assert(meta.Provides["endpoint"], gc.Equals, charm.Relation{
101
101
Name: "endpoint",
102
102
Role: charm.RoleProvider,
103
103
Interface: "http",
104
104
Scope: charm.ScopeGlobal,
106
c.Assert(meta.Provides["admin"], Equals, charm.Relation{
106
c.Assert(meta.Provides["admin"], gc.Equals, charm.Relation{
108
108
Role: charm.RoleProvider,
109
109
Interface: "http",
110
110
Scope: charm.ScopeGlobal,
112
c.Assert(meta.Peers["ring"], Equals, charm.Relation{
112
c.Assert(meta.Peers["ring"], gc.Equals, charm.Relation{
114
114
Role: charm.RolePeer,
115
115
Interface: "riak",
117
117
Scope: charm.ScopeGlobal,
119
c.Assert(meta.Requires, IsNil)
119
c.Assert(meta.Requires, gc.IsNil)
121
121
meta, err = charm.ReadMeta(repoMeta("terracotta"))
123
c.Assert(meta.Provides["dso"], Equals, charm.Relation{
122
c.Assert(err, gc.IsNil)
123
c.Assert(meta.Provides["dso"], gc.Equals, charm.Relation{
125
125
Role: charm.RoleProvider,
126
126
Interface: "terracotta",
128
128
Scope: charm.ScopeGlobal,
130
c.Assert(meta.Peers["server-array"], Equals, charm.Relation{
130
c.Assert(meta.Peers["server-array"], gc.Equals, charm.Relation{
131
131
Name: "server-array",
132
132
Role: charm.RolePeer,
133
133
Interface: "terracotta-server",
135
135
Scope: charm.ScopeGlobal,
137
c.Assert(meta.Requires, IsNil)
137
c.Assert(meta.Requires, gc.IsNil)
139
139
meta, err = charm.ReadMeta(repoMeta("wordpress"))
141
c.Assert(meta.Provides["url"], Equals, charm.Relation{
140
c.Assert(err, gc.IsNil)
141
c.Assert(meta.Provides["url"], gc.Equals, charm.Relation{
143
143
Role: charm.RoleProvider,
144
144
Interface: "http",
145
145
Scope: charm.ScopeGlobal,
147
c.Assert(meta.Requires["db"], Equals, charm.Relation{
147
c.Assert(meta.Requires["db"], gc.Equals, charm.Relation{
149
149
Role: charm.RoleRequirer,
150
150
Interface: "mysql",
152
152
Scope: charm.ScopeGlobal,
154
c.Assert(meta.Requires["cache"], Equals, charm.Relation{
154
c.Assert(meta.Requires["cache"], gc.Equals, charm.Relation{
156
156
Role: charm.RoleRequirer,
157
157
Interface: "varnish",
286
286
// This test ensures test coverage on each of these branches, along
287
287
// with ensuring the conversion object properly raises SchemaError
288
288
// exceptions on invalid data.
289
func (s *MetaSuite) TestIfaceExpander(c *C) {
289
func (s *MetaSuite) TestIfaceExpander(c *gc.C) {
290
290
e := charm.IfaceExpander(nil)
292
292
path := []string{"<pa", "th>"}
294
294
// Shorthand is properly rewritten
295
295
v, err := e.Coerce("http", path)
297
c.Assert(v, DeepEquals, map[string]interface{}{"interface": "http", "limit": nil, "optional": false, "scope": string(charm.ScopeGlobal)})
296
c.Assert(err, gc.IsNil)
297
c.Assert(v, gc.DeepEquals, map[string]interface{}{"interface": "http", "limit": nil, "optional": false, "scope": string(charm.ScopeGlobal)})
299
299
// Defaults are properly applied
300
300
v, err = e.Coerce(map[string]interface{}{"interface": "http"}, path)
302
c.Assert(v, DeepEquals, map[string]interface{}{"interface": "http", "limit": nil, "optional": false, "scope": string(charm.ScopeGlobal)})
301
c.Assert(err, gc.IsNil)
302
c.Assert(v, gc.DeepEquals, map[string]interface{}{"interface": "http", "limit": nil, "optional": false, "scope": string(charm.ScopeGlobal)})
304
304
v, err = e.Coerce(map[string]interface{}{"interface": "http", "limit": 2}, path)
306
c.Assert(v, DeepEquals, map[string]interface{}{"interface": "http", "limit": int64(2), "optional": false, "scope": string(charm.ScopeGlobal)})
305
c.Assert(err, gc.IsNil)
306
c.Assert(v, gc.DeepEquals, map[string]interface{}{"interface": "http", "limit": int64(2), "optional": false, "scope": string(charm.ScopeGlobal)})
308
308
v, err = e.Coerce(map[string]interface{}{"interface": "http", "optional": true}, path)
310
c.Assert(v, DeepEquals, map[string]interface{}{"interface": "http", "limit": nil, "optional": true, "scope": string(charm.ScopeGlobal)})
309
c.Assert(err, gc.IsNil)
310
c.Assert(v, gc.DeepEquals, map[string]interface{}{"interface": "http", "limit": nil, "optional": true, "scope": string(charm.ScopeGlobal)})
312
312
// Invalid data raises an error.
313
313
v, err = e.Coerce(42, path)
314
c.Assert(err, ErrorMatches, "<path>: expected map, got 42")
314
c.Assert(err, gc.ErrorMatches, "<path>: expected map, got 42")
316
316
v, err = e.Coerce(map[string]interface{}{"interface": "http", "optional": nil}, path)
317
c.Assert(err, ErrorMatches, "<path>.optional: expected bool, got nothing")
317
c.Assert(err, gc.ErrorMatches, "<path>.optional: expected bool, got nothing")
319
319
v, err = e.Coerce(map[string]interface{}{"interface": "http", "limit": "none, really"}, path)
320
c.Assert(err, ErrorMatches, "<path>.limit: unexpected value.*")
320
c.Assert(err, gc.ErrorMatches, "<path>.limit: unexpected value.*")
322
322
// Can change default limit
323
323
e = charm.IfaceExpander(1)
324
324
v, err = e.Coerce(map[string]interface{}{"interface": "http"}, path)
326
c.Assert(v, DeepEquals, map[string]interface{}{"interface": "http", "limit": int64(1), "optional": false, "scope": string(charm.ScopeGlobal)})
325
c.Assert(err, gc.IsNil)
326
c.Assert(v, gc.DeepEquals, map[string]interface{}{"interface": "http", "limit": int64(1), "optional": false, "scope": string(charm.ScopeGlobal)})
329
func (s *MetaSuite) TestMetaHooks(c *C) {
329
func (s *MetaSuite) TestMetaHooks(c *gc.C) {
330
330
meta, err := charm.ReadMeta(repoMeta("wordpress"))
331
c.Assert(err, gc.IsNil)
332
332
hooks := meta.Hooks()
333
333
expectedHooks := map[string]bool{