-
Notifications
You must be signed in to change notification settings - Fork 59
/
bundle_test.go
94 lines (80 loc) · 2.48 KB
/
bundle_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
// Copyright 2014 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
package charm_test
import (
"github.com/juju/testing"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"github.com/juju/charm/v12"
)
var _ = gc.Suite(&BundleSuite{})
type BundleSuite struct {
testing.IsolationSuite
}
func (*BundleSuite) TestReadBundleDir(c *gc.C) {
path := bundleDirPath(c, "wordpress-simple")
b, err := charm.ReadBundle(path)
c.Assert(err, gc.IsNil)
c.Assert(b.ContainsOverlays(), jc.IsFalse)
c.Assert(b, gc.FitsTypeOf, (*charm.BundleDir)(nil))
checkWordpressBundle(c, b, path)
}
func (*BundleSuite) TestReadMultiDocBundleDir(c *gc.C) {
path := bundleDirPath(c, "wordpress-simple-multidoc")
b, err := charm.ReadBundle(path)
c.Assert(err, gc.IsNil)
c.Assert(b.ContainsOverlays(), jc.IsTrue)
c.Assert(b, gc.FitsTypeOf, (*charm.BundleDir)(nil))
checkWordpressBundle(c, b, path)
}
func (*BundleSuite) TestReadBundleArchive(c *gc.C) {
path := bundleDirPath(c, "wordpress-simple")
b, err := charm.ReadBundle(path)
c.Assert(err, gc.IsNil)
c.Assert(b.ContainsOverlays(), jc.IsFalse)
c.Assert(b, gc.FitsTypeOf, (*charm.BundleDir)(nil))
checkWordpressBundle(c, b, path)
}
func (*BundleSuite) TestReadMultiDocBundleArchive(c *gc.C) {
path := bundleDirPath(c, "wordpress-simple-multidoc")
b, err := charm.ReadBundle(path)
c.Assert(err, gc.IsNil)
c.Assert(b.ContainsOverlays(), jc.IsTrue)
c.Assert(b, gc.FitsTypeOf, (*charm.BundleDir)(nil))
checkWordpressBundle(c, b, path)
}
func checkWordpressBundle(c *gc.C, b charm.Bundle, path string) {
// Load the charms required by the bundle.
wordpressCharm := readCharmDir(c, "wordpress")
mysqlCharm := readCharmDir(c, "mysql")
bd := b.Data()
c.Assert(bd.RequiredCharms(), jc.DeepEquals, []string{"ch:mysql", "ch:wordpress"})
charms := map[string]charm.Charm{
"ch:wordpress": wordpressCharm,
"ch:mysql": mysqlCharm,
}
err := bd.VerifyWithCharms(verifyOk, nil, nil, charms)
c.Assert(err, gc.IsNil)
c.Assert(bd.Applications, jc.DeepEquals, map[string]*charm.ApplicationSpec{
"wordpress": {
Charm: "ch:wordpress",
},
"mysql": {
Charm: "ch:mysql",
NumUnits: 1,
},
})
c.Assert(bd.Relations, jc.DeepEquals, [][]string{
{"wordpress:db", "mysql:server"},
})
c.Assert(b.ReadMe(), gc.Equals, "A dummy bundle\n")
switch b := b.(type) {
case *charm.BundleArchive:
c.Assert(b.Path, gc.Equals, path)
case *charm.BundleDir:
c.Assert(b.Path, gc.Equals, path)
}
}
func verifyOk(string) error {
return nil
}