~ubuntu-branches/ubuntu/vivid/juju-core/vivid-updates

« back to all changes in this revision

Viewing changes to src/gopkg.in/juju/charm.v5/charmrepo/repo_test.go

  • Committer: Package Import Robot
  • Author(s): Curtis C. Hovey
  • Date: 2015-09-29 19:43:29 UTC
  • mfrom: (47.1.4 wily-proposed)
  • Revision ID: package-import@ubuntu.com-20150929194329-9y496tbic30hc7vp
Tags: 1.24.6-0ubuntu1~15.04.1
Backport of 1.24.6 from wily. (LP: #1500916, #1497087)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2012, 2013 Canonical Ltd.
 
2
// Licensed under the LGPLv3, see LICENCE file for details.
 
3
 
 
4
package charmrepo_test
 
5
 
 
6
import (
 
7
        jc "github.com/juju/testing/checkers"
 
8
        gc "gopkg.in/check.v1"
 
9
        "gopkg.in/juju/charmstore.v4/csclient"
 
10
 
 
11
        "gopkg.in/juju/charm.v5"
 
12
        "gopkg.in/juju/charm.v5/charmrepo"
 
13
        charmtesting "gopkg.in/juju/charm.v5/testing"
 
14
)
 
15
 
 
16
var TestCharms = charmtesting.NewRepo("../internal/test-charm-repo", "quantal")
 
17
 
 
18
type inferRepoSuite struct{}
 
19
 
 
20
var _ = gc.Suite(&inferRepoSuite{})
 
21
 
 
22
var inferRepositoryTests = []struct {
 
23
        url           string
 
24
        localRepoPath string
 
25
        err           string
 
26
}{{
 
27
        url: "cs:trusty/django",
 
28
}, {
 
29
        url: "local:precise/wordpress",
 
30
        err: "path to local repository not specified",
 
31
}, {
 
32
        url:           "local:precise/haproxy-47",
 
33
        localRepoPath: "/tmp/repo-path",
 
34
}}
 
35
 
 
36
func (s *inferRepoSuite) TestInferRepository(c *gc.C) {
 
37
        for i, test := range inferRepositoryTests {
 
38
                c.Logf("test %d: %s", i, test.url)
 
39
                ref := charm.MustParseReference(test.url)
 
40
                repo, err := charmrepo.InferRepository(
 
41
                        ref, charmrepo.NewCharmStoreParams{}, test.localRepoPath)
 
42
                if test.err != "" {
 
43
                        c.Assert(err, gc.ErrorMatches, test.err)
 
44
                        c.Assert(repo, gc.IsNil)
 
45
                        continue
 
46
                }
 
47
                c.Assert(err, jc.ErrorIsNil)
 
48
                switch store := repo.(type) {
 
49
                case *charmrepo.LocalRepository:
 
50
                        c.Assert(store.Path, gc.Equals, test.localRepoPath)
 
51
                case *charmrepo.CharmStore:
 
52
                        c.Assert(store.URL(), gc.Equals, csclient.ServerURL)
 
53
                default:
 
54
                        c.Fatal("unknown repository type")
 
55
                }
 
56
        }
 
57
}