gopkg.in/juju/charm.v6-unstable@v6.0.0-20171026192109-50d0c219b496/bundle_test.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the LGPLv3, see LICENCE file for details. 3 4 package charm_test 5 6 import ( 7 "github.com/juju/testing" 8 jc "github.com/juju/testing/checkers" 9 gc "gopkg.in/check.v1" 10 11 "gopkg.in/juju/charm.v6-unstable" 12 ) 13 14 var _ = gc.Suite(&BundleSuite{}) 15 16 type BundleSuite struct { 17 testing.IsolationSuite 18 } 19 20 func (*BundleSuite) TestReadBundleDir(c *gc.C) { 21 path := bundleDirPath(c, "wordpress-simple") 22 b, err := charm.ReadBundle(path) 23 c.Assert(err, gc.IsNil) 24 c.Assert(b, gc.FitsTypeOf, (*charm.BundleDir)(nil)) 25 checkWordpressBundle(c, b, path) 26 } 27 28 func (*BundleSuite) TestReadBundleArchive(c *gc.C) { 29 path := bundleDirPath(c, "wordpress-simple") 30 b, err := charm.ReadBundle(path) 31 c.Assert(err, gc.IsNil) 32 c.Assert(b, gc.FitsTypeOf, (*charm.BundleDir)(nil)) 33 checkWordpressBundle(c, b, path) 34 } 35 36 func (*BundleSuite) TestReadBundleArchiveWithLegacyServices(c *gc.C) { 37 path := bundleDirPath(c, "wordpress-legacy") 38 b, err := charm.ReadBundle(path) 39 c.Assert(err, gc.IsNil) 40 c.Assert(b, gc.FitsTypeOf, (*charm.BundleDir)(nil)) 41 checkWordpressBundle(c, b, path) 42 } 43 44 func checkWordpressBundle(c *gc.C, b charm.Bundle, path string) { 45 // Load the charms required by the bundle. 46 wordpressCharm := readCharmDir(c, "wordpress") 47 mysqlCharm := readCharmDir(c, "mysql") 48 49 bd := b.Data() 50 c.Assert(bd.RequiredCharms(), jc.DeepEquals, []string{"mysql", "wordpress"}) 51 52 charms := map[string]charm.Charm{ 53 "wordpress": wordpressCharm, 54 "mysql": mysqlCharm, 55 } 56 err := bd.VerifyWithCharms(verifyOk, nil, charms) 57 c.Assert(err, gc.IsNil) 58 59 c.Assert(bd.Applications, jc.DeepEquals, map[string]*charm.ApplicationSpec{ 60 "wordpress": { 61 Charm: "wordpress", 62 }, 63 "mysql": { 64 Charm: "mysql", 65 NumUnits: 1, 66 }, 67 }) 68 c.Assert(bd.Relations, jc.DeepEquals, [][]string{ 69 {"wordpress:db", "mysql:server"}, 70 }) 71 c.Assert(b.ReadMe(), gc.Equals, "A dummy bundle\n") 72 switch b := b.(type) { 73 case *charm.BundleArchive: 74 c.Assert(b.Path, gc.Equals, path) 75 case *charm.BundleDir: 76 c.Assert(b.Path, gc.Equals, path) 77 } 78 } 79 80 func verifyOk(string) error { 81 return nil 82 }