forked from juju/juju
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconn_wallclock_test.go
132 lines (113 loc) · 5.13 KB
/
conn_wallclock_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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Copyright 2016 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package state_test
import (
"github.com/juju/mgo/v2"
"github.com/juju/names/v4"
jc "github.com/juju/testing/checkers"
"github.com/juju/utils/v2"
gc "gopkg.in/check.v1"
"github.com/juju/juju/state"
statetesting "github.com/juju/juju/state/testing"
"github.com/juju/juju/storage"
"github.com/juju/juju/storage/provider"
dummystorage "github.com/juju/juju/storage/provider/dummy"
"github.com/juju/juju/testing"
)
// ConnWithWallClockSuite provides the infrastructure for all other test suites
// (StateSuite, CharmSuite, MachineSuite, etc). This should be deprecated in
// favour of ConnSuite, and tests updated to use the testing clock provided in
// ConnSuite via StateSuite.
type ConnWithWallClockSuite struct {
statetesting.StateWithWallClockSuite
annotations *mgo.Collection
charms *mgo.Collection
machines *mgo.Collection
instanceData *mgo.Collection
relations *mgo.Collection
applications *mgo.Collection
units *mgo.Collection
controllers *mgo.Collection
policy statetesting.MockPolicy
modelTag names.ModelTag
}
func (cs *ConnWithWallClockSuite) SetUpTest(c *gc.C) {
cs.policy = statetesting.MockPolicy{
GetStorageProviderRegistry: func() (storage.ProviderRegistry, error) {
return storage.ChainedProviderRegistry{
dummystorage.StorageProviders(),
provider.CommonStorageProviders(),
}, nil
},
}
cs.StateWithWallClockSuite.NewPolicy = func(*state.State) state.Policy {
return &cs.policy
}
cs.StateWithWallClockSuite.SetUpTest(c)
cs.modelTag = cs.Model.ModelTag()
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.applications = jujuDB.C("applications")
cs.units = jujuDB.C("units")
cs.controllers = jujuDB.C("controllers")
}
func (s *ConnWithWallClockSuite) AddTestingCharm(c *gc.C, name string) *state.Charm {
return state.AddTestingCharm(c, s.State, name)
}
func (s *ConnWithWallClockSuite) AddTestingApplication(c *gc.C, name string, ch *state.Charm) *state.Application {
return state.AddTestingApplication(c, s.State, name, ch)
}
func (s *ConnWithWallClockSuite) AddTestingApplicationWithStorage(c *gc.C, name string, ch *state.Charm, storage map[string]state.StorageConstraints) *state.Application {
return state.AddTestingApplicationWithStorage(c, s.State, name, ch, storage)
}
func (s *ConnWithWallClockSuite) AddTestingApplicationWithBindings(c *gc.C, name string, ch *state.Charm, bindings map[string]string) *state.Application {
return state.AddTestingApplicationWithBindings(c, s.State, name, ch, bindings)
}
func (s *ConnWithWallClockSuite) 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 *ConnWithWallClockSuite) 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 *ConnWithWallClockSuite) 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 *ConnWithWallClockSuite) AddMetaCharm(c *gc.C, name, metaYaml string, revision int) *state.Charm {
return state.AddCustomCharm(c, s.State, name, "metadata.yaml", metaYaml, "quantal", revision)
}
// 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 *ConnWithWallClockSuite) AddMetricsCharm(c *gc.C, name, metricsYaml string, revision int) *state.Charm {
return state.AddCustomCharm(c, s.State, name, "metrics.yaml", metricsYaml, "quantal", revision)
}
// NewStateForModelNamed returns an new model with the given modelName, which
// has a unique UUID, and does not need to be closed when the test completes.
func (s *ConnWithWallClockSuite) NewStateForModelNamed(c *gc.C, modelName string) *state.State {
cfg := testing.CustomModelConfig(c, testing.Attrs{
"name": modelName,
"uuid": utils.MustNewUUID().String(),
})
otherOwner := names.NewLocalUserTag("test-admin")
_, otherState, err := s.Controller.NewModel(state.ModelArgs{
Type: state.ModelTypeIAAS,
CloudName: "dummy",
CloudRegion: "dummy-region",
Config: cfg,
Owner: otherOwner,
StorageProviderRegistry: storage.StaticProviderRegistry{},
})
c.Assert(err, jc.ErrorIsNil)
s.AddCleanup(func(*gc.C) { otherState.Close() })
return otherState
}