1
// Copyright 2011, 2012, 2013 Canonical Ltd.
2
// Licensed under the LGPLv3, see LICENCE file for details.
13
jc "github.com/juju/testing/checkers"
14
gc "gopkg.in/check.v1"
17
"gopkg.in/juju/charm.v5"
18
charmtesting "gopkg.in/juju/charm.v5/testing"
21
func Test(t *stdtesting.T) {
25
var TestCharms = charmtesting.NewRepo("internal/test-charm-repo", "quantal")
27
type CharmSuite struct{}
29
var _ = gc.Suite(&CharmSuite{})
31
func (s *CharmSuite) TestReadCharm(c *gc.C) {
32
bPath := TestCharms.CharmArchivePath(c.MkDir(), "dummy")
33
ch, err := charm.ReadCharm(bPath)
34
c.Assert(err, gc.IsNil)
35
c.Assert(ch.Meta().Name, gc.Equals, "dummy")
36
dPath := TestCharms.CharmDirPath("dummy")
37
ch, err = charm.ReadCharm(dPath)
38
c.Assert(err, gc.IsNil)
39
c.Assert(ch.Meta().Name, gc.Equals, "dummy")
42
func (s *CharmSuite) TestReadCharmDirError(c *gc.C) {
43
ch, err := charm.ReadCharm(c.MkDir())
44
c.Assert(err, gc.NotNil)
45
c.Assert(ch, gc.Equals, nil)
48
func (s *CharmSuite) TestReadCharmArchiveError(c *gc.C) {
49
path := filepath.Join(c.MkDir(), "path")
50
err := ioutil.WriteFile(path, []byte("foo"), 0644)
51
c.Assert(err, gc.IsNil)
52
ch, err := charm.ReadCharm(path)
53
c.Assert(err, gc.NotNil)
54
c.Assert(ch, gc.Equals, nil)
57
func checkDummy(c *gc.C, f charm.Charm, path string) {
58
c.Assert(f.Revision(), gc.Equals, 1)
59
c.Assert(f.Meta().Name, gc.Equals, "dummy")
60
c.Assert(f.Config().Options["title"].Default, gc.Equals, "My Title")
61
c.Assert(f.Actions(), jc.DeepEquals,
63
map[string]charm.ActionSpec{
64
"snapshot": charm.ActionSpec{
65
Description: "Take a snapshot of the database.",
66
Params: map[string]interface{}{
68
"description": "Take a snapshot of the database.",
70
"properties": map[string]interface{}{
71
"outfile": map[string]interface{}{
72
"description": "The file to write out to.",
76
switch f := f.(type) {
77
case *charm.CharmArchive:
78
c.Assert(f.Path, gc.Equals, path)
80
c.Assert(f.Path, gc.Equals, path)
84
type YamlHacker map[interface{}]interface{}
86
func ReadYaml(r io.Reader) YamlHacker {
87
data, err := ioutil.ReadAll(r)
91
m := make(map[interface{}]interface{})
92
err = yaml.Unmarshal(data, m)
99
func (yh YamlHacker) Reader() io.Reader {
100
data, err := yaml.Marshal(yh)
104
return bytes.NewBuffer(data)