launchpad.net/~rogpeppe/juju-core/500-errgo-fix@v0.0.0-20140213181702-000000002356/state/conn_test.go (about) 1 // Copyright 2012, 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package state_test 5 6 import ( 7 stdtesting "testing" 8 9 "labix.org/v2/mgo" 10 gc "launchpad.net/gocheck" 11 12 "launchpad.net/juju-core/state" 13 "launchpad.net/juju-core/testing" 14 "launchpad.net/juju-core/testing/testbase" 15 ) 16 17 // TestPackage integrates the tests into gotest. 18 func TestPackage(t *stdtesting.T) { 19 testing.MgoTestPackage(t) 20 } 21 22 // ConnSuite provides the infrastructure for all other 23 // test suites (StateSuite, CharmSuite, MachineSuite, etc). 24 type ConnSuite struct { 25 testing.MgoSuite 26 testbase.LoggingSuite 27 annotations *mgo.Collection 28 charms *mgo.Collection 29 machines *mgo.Collection 30 relations *mgo.Collection 31 services *mgo.Collection 32 units *mgo.Collection 33 stateServers *mgo.Collection 34 State *state.State 35 } 36 37 func (cs *ConnSuite) SetUpSuite(c *gc.C) { 38 cs.LoggingSuite.SetUpSuite(c) 39 cs.MgoSuite.SetUpSuite(c) 40 } 41 42 func (cs *ConnSuite) TearDownSuite(c *gc.C) { 43 cs.MgoSuite.TearDownSuite(c) 44 cs.LoggingSuite.TearDownSuite(c) 45 } 46 47 func (cs *ConnSuite) SetUpTest(c *gc.C) { 48 cs.LoggingSuite.SetUpTest(c) 49 cs.MgoSuite.SetUpTest(c) 50 cs.State = state.TestingInitialize(c, nil) 51 cs.annotations = cs.MgoSuite.Session.DB("juju").C("annotations") 52 cs.charms = cs.MgoSuite.Session.DB("juju").C("charms") 53 cs.machines = cs.MgoSuite.Session.DB("juju").C("machines") 54 cs.relations = cs.MgoSuite.Session.DB("juju").C("relations") 55 cs.services = cs.MgoSuite.Session.DB("juju").C("services") 56 cs.units = cs.MgoSuite.Session.DB("juju").C("units") 57 cs.stateServers = cs.MgoSuite.Session.DB("juju").C("stateServers") 58 cs.State.AddUser("admin", "pass") 59 } 60 61 func (cs *ConnSuite) TearDownTest(c *gc.C) { 62 cs.State.Close() 63 cs.MgoSuite.TearDownTest(c) 64 cs.LoggingSuite.TearDownTest(c) 65 } 66 67 func (s *ConnSuite) AddTestingCharm(c *gc.C, name string) *state.Charm { 68 return state.AddTestingCharm(c, s.State, name) 69 } 70 71 func (s *ConnSuite) AddTestingService(c *gc.C, name string, ch *state.Charm) *state.Service { 72 return state.AddTestingService(c, s.State, name, ch) 73 } 74 75 func (s *ConnSuite) AddSeriesCharm(c *gc.C, name, series string) *state.Charm { 76 return state.AddCustomCharm(c, s.State, name, "", "", series, -1) 77 } 78 79 // AddConfigCharm clones a testing charm, replaces its config with 80 // the given YAML string and adds it to the state, using the given 81 // revision. 82 func (s *ConnSuite) AddConfigCharm(c *gc.C, name, configYaml string, revision int) *state.Charm { 83 return state.AddCustomCharm(c, s.State, name, "config.yaml", configYaml, "quantal", revision) 84 } 85 86 // AddMetaCharm clones a testing charm, replaces its metadata with the 87 // given YAML string and adds it to the state, using the given revision. 88 func (s *ConnSuite) AddMetaCharm(c *gc.C, name, metaYaml string, revsion int) *state.Charm { 89 return state.AddCustomCharm(c, s.State, name, "metadata.yaml", metaYaml, "quantal", revsion) 90 }