7
. "launchpad.net/gocheck"
8
"launchpad.net/juju-core/charm"
9
"launchpad.net/juju-core/environs/config"
10
"launchpad.net/juju-core/testing"
15
// TestingEnvironConfig returns a default environment configuration.
16
func TestingEnvironConfig(c *C) *config.Config {
17
cfg, err := config.New(map[string]interface{}{
20
"default-series": "test-series",
21
"authorized-keys": "test-keys",
22
"agent-version": "9.9.9.9",
23
"ca-cert": testing.CACert,
30
// TestingInitialize initializes the state and returns it. If state was not
31
// already initialized, and cfg is nil, the minimal default environment
32
// configuration will be used.
33
func TestingInitialize(c *C, cfg *config.Config) *State {
35
cfg = TestingEnvironConfig(c)
37
st, err := Initialize(TestingStateInfo(), cfg, TestingDialOpts())
45
RelationDoc relationDoc
50
func (doc *MachineDoc) String() string {
51
m := &Machine{doc: machineDoc(*doc)}
55
func ServiceSettingsRefCount(st *State, serviceName string, curl *charm.URL) (int, error) {
56
key := serviceSettingsKey(serviceName, curl)
57
var doc settingsRefsDoc
58
if err := st.settingsrefs.FindId(key).One(&doc); err == nil {
59
return doc.RefCount, nil
61
return 0, mgo.ErrNotFound
64
func AddTestingCharm(c *C, st *State, name string) *Charm {
65
return addCharm(c, st, "series", testing.Charms.Dir(name))
68
func AddCustomCharm(c *C, st *State, name, filename, content, series string, revision int) *Charm {
69
path := testing.Charms.ClonedDirPath(c.MkDir(), name)
71
config := filepath.Join(path, filename)
72
err := ioutil.WriteFile(config, []byte(content), 0644)
75
ch, err := charm.ReadDir(path)
78
ch.SetRevision(revision)
80
return addCharm(c, st, series, ch)
83
func addCharm(c *C, st *State, series string, ch charm.Charm) *Charm {
84
ident := fmt.Sprintf("%s-%s-%d", series, ch.Meta().Name, ch.Revision())
85
curl := charm.MustParseURL("local:" + series + "/" + ident)
86
bundleURL, err := url.Parse("http://bundles.example.com/" + ident)
88
sch, err := st.AddCharm(ch, curl, bundleURL, ident+"-sha256")
94
logSize = logSizeTests