~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/gopkg.in/juju/charmstore.v5-unstable/internal/charmstore/common_test.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2016 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package charmstore // import "gopkg.in/juju/charmstore.v5-unstable/internal/charmstore"
 
5
 
 
6
import (
 
7
        gc "gopkg.in/check.v1"
 
8
        "gopkg.in/juju/charm.v6-unstable"
 
9
        "gopkg.in/juju/charmrepo.v2-unstable/csclient/params"
 
10
        "gopkg.in/macaroon-bakery.v1/bakery"
 
11
 
 
12
        "gopkg.in/juju/charmstore.v5-unstable/internal/router"
 
13
        "gopkg.in/juju/charmstore.v5-unstable/internal/storetesting"
 
14
)
 
15
 
 
16
type commonSuite struct {
 
17
        storetesting.IsolatedMgoESSuite
 
18
        index string
 
19
}
 
20
 
 
21
// addRequiredCharms adds any charms required by the given
 
22
// bundle that are not already in the store.
 
23
func (s *commonSuite) addRequiredCharms(c *gc.C, bundle charm.Bundle) {
 
24
        store := s.newStore(c, true)
 
25
        defer store.Close()
 
26
        for _, svc := range bundle.Data().Services {
 
27
                u := charm.MustParseURL(svc.Charm)
 
28
                if _, err := store.FindBestEntity(u, params.NoChannel, nil); err == nil {
 
29
                        continue
 
30
                }
 
31
                if u.Revision == -1 {
 
32
                        u.Revision = 0
 
33
                }
 
34
                var rurl router.ResolvedURL
 
35
                rurl.URL = *u
 
36
                ch := storetesting.Charms.CharmDir(u.Name)
 
37
                if len(ch.Meta().Series) == 0 && u.Series == "" {
 
38
                        rurl.URL.Series = "trusty"
 
39
                }
 
40
                if u.User == "" {
 
41
                        rurl.URL.User = "charmers"
 
42
                        rurl.PromulgatedRevision = rurl.URL.Revision
 
43
                } else {
 
44
                        rurl.PromulgatedRevision = -1
 
45
                }
 
46
                err := store.AddCharmWithArchive(&rurl, ch)
 
47
                c.Assert(err, gc.IsNil)
 
48
                err = store.Publish(&rurl, params.StableChannel)
 
49
                c.Assert(err, gc.IsNil)
 
50
        }
 
51
}
 
52
 
 
53
func (s *commonSuite) newStore(c *gc.C, withES bool) *Store {
 
54
        var si *SearchIndex
 
55
        if withES {
 
56
                si = &SearchIndex{s.ES, s.TestIndex}
 
57
        }
 
58
        p, err := NewPool(s.Session.DB("juju_test"), si, &bakery.NewServiceParams{}, ServerParams{})
 
59
        c.Assert(err, gc.IsNil)
 
60
        store := p.Store()
 
61
        p.Close()
 
62
        return store
 
63
}