~rogpeppe/juju-core/438-local-instance-Addresses

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
package formula_test

import (
	"archive/zip"
	. "launchpad.net/gocheck"
	"launchpad.net/ensemble/go/formula"
	"os"
	"path/filepath"
)

func repoDir(name string) (path string) {
	return filepath.Join("testrepo", name)
}

func (s *S) TestReadDir(c *C) {
	path := repoDir("dummy")
	dir, err := formula.ReadDir(path)
	c.Assert(err, IsNil)
	c.Assert(dir.Path, Equals, path)
	c.Assert(dir.Meta().Name, Equals, "dummy")
	c.Assert(dir.Config().Options["title"].Default, Equals, "My Title")
}

func (s *S) TestBundleTo(c *C) {
	dir, err := formula.ReadDir(repoDir("dummy"))
	c.Assert(err, IsNil)

	path := filepath.Join(c.MkDir(), "bundle.charm")
	file, err := os.Create(path)
	c.Assert(err, IsNil)
	err = dir.BundleTo(file)
	file.Close()
	c.Assert(err, IsNil)

	zipr, err := zip.OpenReader(path)
	c.Assert(err, IsNil)
	defer zipr.Close()

	var metaf *zip.File
	for _, f := range zipr.File {
		c.Logf("Bundled file: %s", f.Name)
		switch f.Name {
		case "metadata.yaml":
			metaf = f
		case "build/ignored":
			c.Fatal("bundle includes build/*")
		}
	}

	c.Assert(metaf, NotNil)
	reader, err := metaf.Open()
	c.Assert(err, IsNil)
	defer reader.Close()
	meta, err := formula.ReadMeta(reader)
	c.Assert(err, IsNil)
	c.Assert(meta.Name, Equals, "dummy")
}