~sinzui/ubuntu/vivid/juju-core/vivid-1.24.6

« back to all changes in this revision

Viewing changes to src/gopkg.in/juju/charm.v4/bundledir_test.go

  • Committer: Curtis Hovey
  • Date: 2015-09-30 14:14:54 UTC
  • mfrom: (1.1.34)
  • Revision ID: curtis@hovey.name-20150930141454-o3ldf23dzyjio6c0
Backport of 1.24.6 from wily. (LP: #1500916)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright 2014 Canonical Ltd.
2
 
// Licensed under the AGPLv3, 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
 
        "gopkg.in/juju/charm.v4"
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 := TestCharms.BundleDirPath("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 := 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)
36
 
}
37
 
 
38
 
func (s *BundleDirSuite) TestArchiveTo(c *gc.C) {
39
 
        baseDir := c.MkDir()
40
 
        charmDir := TestCharms.ClonedBundleDirPath(baseDir, "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
 
}