-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconn_test.go
108 lines (87 loc) · 3.79 KB
/
conn_test.go
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright 2012, 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package state_test
import (
stdtesting "testing"
"github.com/juju/names"
gc "gopkg.in/check.v1"
"gopkg.in/mgo.v2"
"github.com/juju/juju/state"
statetesting "github.com/juju/juju/state/testing"
"github.com/juju/juju/testing"
"github.com/juju/juju/testing/factory"
)
// TestPackage integrates the tests into gotest.
func TestPackage(t *stdtesting.T) {
testing.MgoTestPackage(t)
}
// ConnSuite provides the infrastructure for all other
// test suites (StateSuite, CharmSuite, MachineSuite, etc).
type ConnSuite struct {
statetesting.StateSuite
annotations *mgo.Collection
charms *mgo.Collection
machines *mgo.Collection
instanceData *mgo.Collection
relations *mgo.Collection
services *mgo.Collection
units *mgo.Collection
stateServers *mgo.Collection
policy statetesting.MockPolicy
factory *factory.Factory
envTag names.EnvironTag
}
func (cs *ConnSuite) SetUpTest(c *gc.C) {
c.Log("SetUpTest")
cs.policy = statetesting.MockPolicy{}
cs.StateSuite.Policy = &cs.policy
cs.StateSuite.SetUpTest(c)
cs.envTag = cs.State.EnvironTag()
cs.factory = factory.NewFactory(cs.State)
jujuDB := cs.MgoSuite.Session.DB("juju")
cs.annotations = jujuDB.C("annotations")
cs.charms = jujuDB.C("charms")
cs.machines = jujuDB.C("machines")
cs.instanceData = jujuDB.C("instanceData")
cs.relations = jujuDB.C("relations")
cs.services = jujuDB.C("services")
cs.units = jujuDB.C("units")
cs.stateServers = jujuDB.C("stateServers")
c.Log("SetUpTest done")
}
func (s *ConnSuite) AddTestingCharm(c *gc.C, name string) *state.Charm {
return state.AddTestingCharm(c, s.State, name)
}
func (s *ConnSuite) AddTestingService(c *gc.C, name string, ch *state.Charm) *state.Service {
return state.AddTestingService(c, s.State, name, ch, s.Owner)
}
func (s *ConnSuite) AddTestingServiceWithNetworks(c *gc.C, name string, ch *state.Charm, networks []string) *state.Service {
return state.AddTestingServiceWithNetworks(c, s.State, name, ch, s.Owner, networks)
}
func (s *ConnSuite) AddTestingServiceWithStorage(c *gc.C, name string, ch *state.Charm, storage map[string]state.StorageConstraints) *state.Service {
return state.AddTestingServiceWithStorage(c, s.State, name, ch, s.Owner, storage)
}
func (s *ConnSuite) AddSeriesCharm(c *gc.C, name, series string) *state.Charm {
return state.AddCustomCharm(c, s.State, name, "", "", series, -1)
}
// AddConfigCharm clones a testing charm, replaces its config with
// the given YAML string and adds it to the state, using the given
// revision.
func (s *ConnSuite) AddConfigCharm(c *gc.C, name, configYaml string, revision int) *state.Charm {
return state.AddCustomCharm(c, s.State, name, "config.yaml", configYaml, "quantal", revision)
}
// AddActionsCharm clones a testing charm, replaces its actions schema with
// the given YAML, and adds it to the state, using the given revision.
func (s *ConnSuite) AddActionsCharm(c *gc.C, name, actionsYaml string, revision int) *state.Charm {
return state.AddCustomCharm(c, s.State, name, "actions.yaml", actionsYaml, "quantal", revision)
}
// AddMetaCharm clones a testing charm, replaces its metadata with the
// given YAML string and adds it to the state, using the given revision.
func (s *ConnSuite) AddMetaCharm(c *gc.C, name, metaYaml string, revsion int) *state.Charm {
return state.AddCustomCharm(c, s.State, name, "metadata.yaml", metaYaml, "quantal", revsion)
}
// AddMetricsCharm clones a testing charm, replaces its metrics declaration with the
// given YAML string and adds it to the state, using the given revision.
func (s *ConnSuite) AddMetricsCharm(c *gc.C, name, metricsYaml string, revsion int) *state.Charm {
return state.AddCustomCharm(c, s.State, name, "metrics.yaml", metricsYaml, "quantal", revsion)
}