~fwereade/pyjuju/go-place-unit

« back to all changes in this revision

Viewing changes to charm/charm_test.go

  • Committer: William Reade
  • Date: 2012-06-06 09:57:29 UTC
  • mfrom: (193.1.10 go)
  • Revision ID: fwereade@gmail.com-20120606095729-gvsqo1auqspzog9j
merge parent

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
        . "launchpad.net/gocheck"
8
8
        "launchpad.net/goyaml"
9
9
        "launchpad.net/juju/go/charm"
10
 
        "testing"
 
10
        "launchpad.net/juju/go/testing"
 
11
        stdtesting "testing"
11
12
)
12
13
 
13
 
func Test(t *testing.T) {
 
14
func Test(t *stdtesting.T) {
14
15
        TestingT(t)
15
16
}
16
17
 
17
 
type S struct{}
18
 
 
19
 
var _ = Suite(&S{})
20
 
 
21
 
func (s *S) SetUpSuite(c *C) {}
 
18
type CharmSuite struct{}
 
19
 
 
20
var _ = Suite(&CharmSuite{})
 
21
 
 
22
func (s *CharmSuite) TestRead(c *C) {
 
23
        bPath := testing.Charms.BundlePath(c.MkDir(), "dummy")
 
24
        ch, err := charm.Read(bPath)
 
25
        c.Assert(err, IsNil)
 
26
        c.Assert(ch.Meta().Name, Equals, "dummy")
 
27
        dPath := testing.Charms.DirPath("dummy")
 
28
        ch, err = charm.Read(dPath)
 
29
        c.Assert(err, IsNil)
 
30
        c.Assert(ch.Meta().Name, Equals, "dummy")
 
31
}
 
32
 
 
33
var inferRepoTests = []struct {
 
34
        name   string
 
35
        series string
 
36
        path   string
 
37
        curl   string
 
38
}{
 
39
        {"wordpress", "precise", "anything", "cs:precise/wordpress"},
 
40
        {"oneiric/wordpress", "anything", "anything", "cs:oneiric/wordpress"},
 
41
        {"cs:oneiric/wordpress", "anything", "anything", "cs:oneiric/wordpress"},
 
42
        {"local:wordpress", "precise", "/some/path", "local:precise/wordpress"},
 
43
        {"local:oneiric/wordpress", "anything", "/some/path", "local:oneiric/wordpress"},
 
44
}
 
45
 
 
46
func (s *CharmSuite) TestInferRepository(c *C) {
 
47
        for _, t := range inferRepoTests {
 
48
                repo, curl, err := charm.InferRepository(t.name, t.series, t.path)
 
49
                c.Assert(err, IsNil)
 
50
                expectCurl := charm.MustParseURL(t.curl)
 
51
                c.Assert(curl, DeepEquals, expectCurl)
 
52
                if localRepo, ok := repo.(*charm.LocalRepository); ok {
 
53
                        c.Assert(localRepo.Path, Equals, t.path)
 
54
                        c.Assert(curl.Schema, Equals, "local")
 
55
                } else {
 
56
                        c.Assert(curl.Schema, Equals, "cs")
 
57
                }
 
58
        }
 
59
        _, _, err := charm.InferRepository("local:whatever", "series", "")
 
60
        c.Assert(err, ErrorMatches, "path to local repository not specified")
 
61
}
22
62
 
23
63
func checkDummy(c *C, f charm.Charm, path string) {
24
64
        c.Assert(f.Revision(), Equals, 1)