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
58
59
60
61
62
63
64
65
66
67
|
// Copyright 2016 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package charmstore // import "gopkg.in/juju/charmstore.v5-unstable/internal/charmstore"
import (
gc "gopkg.in/check.v1"
"gopkg.in/juju/charm.v6-unstable"
"gopkg.in/juju/charmrepo.v2-unstable/csclient/params"
"gopkg.in/macaroon-bakery.v1/bakery"
"gopkg.in/juju/charmstore.v5-unstable/internal/router"
"gopkg.in/juju/charmstore.v5-unstable/internal/storetesting"
)
type commonSuite struct {
storetesting.IsolatedMgoESSuite
index string
}
// addRequiredCharms adds any charms required by the given
// bundle that are not already in the store.
func (s *commonSuite) addRequiredCharms(c *gc.C, bundle charm.Bundle) {
store := s.newStore(c, true)
defer store.Close()
addRequiredCharms(c, store, bundle)
}
func (s *commonSuite) newStore(c *gc.C, withElasticSearch bool) *Store {
var si *SearchIndex
if withElasticSearch {
si = &SearchIndex{s.ES, s.TestIndex}
}
p, err := NewPool(s.Session.DB("juju_test"), si, &bakery.NewServiceParams{}, ServerParams{})
c.Assert(err, gc.IsNil)
store := p.Store()
defer p.Close()
return store
}
func addRequiredCharms(c *gc.C, store *Store, bundle charm.Bundle) {
for _, app := range bundle.Data().Applications {
u := charm.MustParseURL(app.Charm)
if _, err := store.FindBestEntity(u, params.NoChannel, nil); err == nil {
continue
}
if u.Revision == -1 {
u.Revision = 0
}
var rurl router.ResolvedURL
rurl.URL = *u
ch := storetesting.Charms.CharmDir(u.Name)
if len(ch.Meta().Series) == 0 && u.Series == "" {
rurl.URL.Series = "trusty"
}
if u.User == "" {
rurl.URL.User = "charmers"
rurl.PromulgatedRevision = rurl.URL.Revision
} else {
rurl.PromulgatedRevision = -1
}
err := store.AddCharmWithArchive(&rurl, ch)
c.Assert(err, gc.IsNil)
err = store.Publish(&rurl, nil, params.StableChannel)
c.Assert(err, gc.IsNil)
}
}
|