forked from juju/charmrepo
/
repo_test.go
57 lines (49 loc) · 1.46 KB
/
repo_test.go
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
// Copyright 2012, 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package charmrepo_test
import (
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"gopkg.in/juju/charm.v6-unstable"
"gopkg.in/juju/charmrepo.v0"
"gopkg.in/juju/charmrepo.v0/csclient"
charmtesting "gopkg.in/juju/charmrepo.v0/testing"
)
var TestCharms = charmtesting.NewRepo("internal/test-charm-repo", "quantal")
type inferRepoSuite struct{}
var _ = gc.Suite(&inferRepoSuite{})
var inferRepositoryTests = []struct {
url string
localRepoPath string
err string
}{{
url: "cs:trusty/django",
}, {
url: "local:precise/wordpress",
err: "path to local repository not specified",
}, {
url: "local:precise/haproxy-47",
localRepoPath: "/tmp/repo-path",
}}
func (s *inferRepoSuite) TestInferRepository(c *gc.C) {
for i, test := range inferRepositoryTests {
c.Logf("test %d: %s", i, test.url)
ref := charm.MustParseReference(test.url)
repo, err := charmrepo.InferRepository(
ref, charmrepo.NewCharmStoreParams{}, test.localRepoPath)
if test.err != "" {
c.Assert(err, gc.ErrorMatches, test.err)
c.Assert(repo, gc.IsNil)
continue
}
c.Assert(err, jc.ErrorIsNil)
switch store := repo.(type) {
case *charmrepo.LocalRepository:
c.Assert(store.Path, gc.Equals, test.localRepoPath)
case *charmrepo.CharmStore:
c.Assert(store.URL(), gc.Equals, csclient.ServerURL)
default:
c.Fatal("unknown repository type")
}
}
}