github.com/juju/charm/v11@v11.2.0/bundledir_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 "os" 8 "path/filepath" 9 10 "github.com/juju/testing" 11 gc "gopkg.in/check.v1" 12 13 "github.com/juju/charm/v11" 14 ) 15 16 type BundleDirSuite struct { 17 testing.IsolationSuite 18 } 19 20 var _ = gc.Suite(&BundleDirSuite{}) 21 22 func (s *BundleDirSuite) TestReadBundleDir(c *gc.C) { 23 path := bundleDirPath(c, "wordpress-simple") 24 dir, err := charm.ReadBundleDir(path) 25 c.Assert(err, gc.IsNil) 26 checkWordpressBundle(c, dir, path) 27 } 28 29 func (s *BundleDirSuite) TestReadBundleDirWithoutREADME(c *gc.C) { 30 path := cloneDir(c, bundleDirPath(c, "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) 36 } 37 38 func (s *BundleDirSuite) TestArchiveTo(c *gc.C) { 39 baseDir := c.MkDir() 40 charmDir := cloneDir(c, bundleDirPath(c, "wordpress-simple")) 41 s.assertArchiveTo(c, baseDir, charmDir) 42 } 43 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) 51 file.Close() 52 c.Assert(err, gc.IsNil) 53 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()) 58 }