1
// Copyright 2014 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
10
"github.com/juju/testing"
11
gc "gopkg.in/check.v1"
13
"gopkg.in/juju/charm.v4"
16
type BundleDirSuite struct {
17
testing.IsolationSuite
20
var _ = gc.Suite(&BundleDirSuite{})
22
func (s *BundleDirSuite) TestReadBundleDir(c *gc.C) {
23
path := TestCharms.BundleDirPath("wordpress-simple")
24
dir, err := charm.ReadBundleDir(path)
25
c.Assert(err, gc.IsNil)
26
checkWordpressBundle(c, dir, path)
29
func (s *BundleDirSuite) TestReadBundleDirWithoutREADME(c *gc.C) {
30
path := TestCharms.ClonedBundleDirPath(c.MkDir(), "wordpress-simple")
31
err := os.Remove(filepath.Join(path, "README.md"))
32
c.Assert(err, gc.IsNil)
33
dir, err := charm.ReadBundleDir(path)
34
c.Assert(err, gc.ErrorMatches, "cannot read README file: .*")
35
c.Assert(dir, gc.IsNil)
38
func (s *BundleDirSuite) TestArchiveTo(c *gc.C) {
40
charmDir := TestCharms.ClonedBundleDirPath(baseDir, "wordpress-simple")
41
s.assertArchiveTo(c, baseDir, charmDir)
44
func (s *BundleDirSuite) assertArchiveTo(c *gc.C, baseDir, bundleDir string) {
45
dir, err := charm.ReadBundleDir(bundleDir)
46
c.Assert(err, gc.IsNil)
47
path := filepath.Join(baseDir, "archive.bundle")
48
file, err := os.Create(path)
49
c.Assert(err, gc.IsNil)
50
err = dir.ArchiveTo(file)
52
c.Assert(err, gc.IsNil)
54
archive, err := charm.ReadBundleArchive(path)
55
c.Assert(err, gc.IsNil)
56
c.Assert(archive.ReadMe(), gc.Equals, dir.ReadMe())
57
c.Assert(archive.Data(), gc.DeepEquals, dir.Data())