~nskaggs/+junk/xenial-test

« back to all changes in this revision

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

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

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
        addRequiredCharms(c, store, bundle)
 
27
}
 
28
 
 
29
func (s *commonSuite) newStore(c *gc.C, withElasticSearch bool) *Store {
 
30
        var si *SearchIndex
 
31
        if withElasticSearch {
 
32
                si = &SearchIndex{s.ES, s.TestIndex}
 
33
        }
 
34
        p, err := NewPool(s.Session.DB("juju_test"), si, &bakery.NewServiceParams{}, ServerParams{})
 
35
        c.Assert(err, gc.IsNil)
 
36
        store := p.Store()
 
37
        defer p.Close()
 
38
        return store
 
39
}
 
40
 
 
41
func addRequiredCharms(c *gc.C, store *Store, bundle charm.Bundle) {
 
42
        for _, app := range bundle.Data().Applications {
 
43
                u := charm.MustParseURL(app.Charm)
 
44
                if _, err := store.FindBestEntity(u, params.NoChannel, nil); err == nil {
 
45
                        continue
 
46
                }
 
47
                if u.Revision == -1 {
 
48
                        u.Revision = 0
 
49
                }
 
50
                var rurl router.ResolvedURL
 
51
                rurl.URL = *u
 
52
                ch := storetesting.Charms.CharmDir(u.Name)
 
53
                if len(ch.Meta().Series) == 0 && u.Series == "" {
 
54
                        rurl.URL.Series = "trusty"
 
55
                }
 
56
                if u.User == "" {
 
57
                        rurl.URL.User = "charmers"
 
58
                        rurl.PromulgatedRevision = rurl.URL.Revision
 
59
                } else {
 
60
                        rurl.PromulgatedRevision = -1
 
61
                }
 
62
                err := store.AddCharmWithArchive(&rurl, ch)
 
63
                c.Assert(err, gc.IsNil)
 
64
                err = store.Publish(&rurl, nil, params.StableChannel)
 
65
                c.Assert(err, gc.IsNil)
 
66
        }
 
67
}