github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/state/testing/suite_wallclock.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package testing 5 6 import ( 7 mgotesting "github.com/juju/mgo/v3/testing" 8 "github.com/juju/names/v5" 9 jc "github.com/juju/testing/checkers" 10 gc "gopkg.in/check.v1" 11 12 "github.com/juju/juju/cloud" 13 "github.com/juju/juju/environs/config" 14 "github.com/juju/juju/state" 15 coretesting "github.com/juju/juju/testing" 16 "github.com/juju/juju/testing/factory" 17 ) 18 19 var _ = gc.Suite(&StateWithWallClockSuite{}) 20 21 // StateWithWallClockSuite provides setup and teardown for tests that require a 22 // state.State. This should be deprecated in favour of StateSuite, and tests 23 // updated to use the testing clock StateSuite provides. 24 type StateWithWallClockSuite struct { 25 mgotesting.MgoSuite 26 coretesting.BaseSuite 27 NewPolicy state.NewPolicyFunc 28 Controller *state.Controller 29 StatePool *state.StatePool 30 State *state.State 31 Model *state.Model 32 Owner names.UserTag 33 Factory *factory.Factory 34 InitialConfig *config.Config 35 ControllerInheritedConfig map[string]interface{} 36 RegionConfig cloud.RegionConfig 37 } 38 39 func (s *StateWithWallClockSuite) SetUpSuite(c *gc.C) { 40 s.MgoSuite.SetUpSuite(c) 41 s.BaseSuite.SetUpSuite(c) 42 } 43 44 func (s *StateWithWallClockSuite) TearDownSuite(c *gc.C) { 45 s.BaseSuite.TearDownSuite(c) 46 s.MgoSuite.TearDownSuite(c) 47 } 48 49 func (s *StateWithWallClockSuite) SetUpTest(c *gc.C) { 50 s.MgoSuite.SetUpTest(c) 51 s.BaseSuite.SetUpTest(c) 52 53 s.Owner = names.NewLocalUserTag("test-admin") 54 s.Controller = Initialize(c, s.Owner, s.InitialConfig, s.ControllerInheritedConfig, s.RegionConfig, s.NewPolicy) 55 s.AddCleanup(func(*gc.C) { 56 s.Controller.Close() 57 }) 58 s.StatePool = s.Controller.StatePool() 59 var err error 60 s.State, err = s.StatePool.SystemState() 61 c.Assert(err, jc.ErrorIsNil) 62 model, err := s.State.Model() 63 c.Assert(err, jc.ErrorIsNil) 64 s.Model = model 65 66 s.Factory = factory.NewFactory(s.State, s.StatePool) 67 } 68 69 func (s *StateWithWallClockSuite) TearDownTest(c *gc.C) { 70 s.BaseSuite.TearDownTest(c) 71 s.MgoSuite.TearDownTest(c) 72 }