github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/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  	"github.com/juju/testing"
     8  	jc "github.com/juju/testing/checkers"
     9  	gc "gopkg.in/check.v1"
    10  	"gopkg.in/juju/names.v2"
    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  	testing.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  	s.State = s.StatePool.SystemState()
    60  	model, err := s.State.Model()
    61  	c.Assert(err, jc.ErrorIsNil)
    62  	s.Model = model
    63  
    64  	s.Factory = factory.NewFactory(s.State, s.StatePool)
    65  }
    66  
    67  func (s *StateWithWallClockSuite) TearDownTest(c *gc.C) {
    68  	s.BaseSuite.TearDownTest(c)
    69  	s.MgoSuite.TearDownTest(c)
    70  }