-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconn_test.go
109 lines (92 loc) · 3.67 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
109
// Copyright 2012, 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package state_test
import (
stdtesting "testing"
gitjujutesting "github.com/juju/testing"
"labix.org/v2/mgo"
gc "launchpad.net/gocheck"
"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 {
gitjujutesting.MgoSuite
testing.BaseSuite
annotations *mgo.Collection
charms *mgo.Collection
machines *mgo.Collection
relations *mgo.Collection
services *mgo.Collection
units *mgo.Collection
stateServers *mgo.Collection
State *state.State
policy statetesting.MockPolicy
factory *factory.Factory
}
func (cs *ConnSuite) SetUpSuite(c *gc.C) {
cs.BaseSuite.SetUpSuite(c)
cs.MgoSuite.SetUpSuite(c)
}
func (cs *ConnSuite) TearDownSuite(c *gc.C) {
cs.MgoSuite.TearDownSuite(c)
cs.BaseSuite.TearDownSuite(c)
}
func (cs *ConnSuite) SetUpTest(c *gc.C) {
cs.BaseSuite.SetUpTest(c)
cs.MgoSuite.SetUpTest(c)
cs.policy = statetesting.MockPolicy{}
cs.State = state.TestingInitialize(c, nil, &cs.policy)
cs.annotations = cs.MgoSuite.Session.DB("juju").C("annotations")
cs.charms = cs.MgoSuite.Session.DB("juju").C("charms")
cs.machines = cs.MgoSuite.Session.DB("juju").C("machines")
cs.relations = cs.MgoSuite.Session.DB("juju").C("relations")
cs.services = cs.MgoSuite.Session.DB("juju").C("services")
cs.units = cs.MgoSuite.Session.DB("juju").C("units")
cs.stateServers = cs.MgoSuite.Session.DB("juju").C("stateServers")
cs.State.AddAdminUser("pass")
cs.factory = factory.NewFactory(cs.State, c)
}
func (cs *ConnSuite) TearDownTest(c *gc.C) {
if cs.State != nil {
// If setup fails, we don't have a State yet
cs.State.Close()
}
cs.MgoSuite.TearDownTest(c)
cs.BaseSuite.TearDownTest(c)
}
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)
}
func (s *ConnSuite) AddTestingServiceWithNetworks(c *gc.C, name string, ch *state.Charm, networks []string) *state.Service {
return state.AddTestingServiceWithNetworks(c, s.State, name, ch, networks)
}
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)
}