github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/state/testing/suite.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package testing
     5  
     6  import (
     7  	jujutesting "github.com/juju/testing"
     8  	gc "gopkg.in/check.v1"
     9  	"gopkg.in/juju/names.v2"
    10  
    11  	"github.com/juju/juju/cloud"
    12  	"github.com/juju/juju/environs/config"
    13  	"github.com/juju/juju/state"
    14  	"github.com/juju/juju/testing"
    15  	"github.com/juju/juju/testing/factory"
    16  )
    17  
    18  var _ = gc.Suite(&StateSuite{})
    19  
    20  // StateSuite provides setup and teardown for tests that require a
    21  // state.State.
    22  type StateSuite struct {
    23  	jujutesting.MgoSuite
    24  	testing.BaseSuite
    25  	NewPolicy                 state.NewPolicyFunc
    26  	State                     *state.State
    27  	Owner                     names.UserTag
    28  	Factory                   *factory.Factory
    29  	InitialConfig             *config.Config
    30  	ControllerInheritedConfig map[string]interface{}
    31  	RegionConfig              cloud.RegionConfig
    32  	Clock                     *jujutesting.Clock
    33  }
    34  
    35  func (s *StateSuite) SetUpSuite(c *gc.C) {
    36  	s.MgoSuite.SetUpSuite(c)
    37  	s.BaseSuite.SetUpSuite(c)
    38  }
    39  
    40  func (s *StateSuite) TearDownSuite(c *gc.C) {
    41  	s.BaseSuite.TearDownSuite(c)
    42  	s.MgoSuite.TearDownSuite(c)
    43  }
    44  
    45  func (s *StateSuite) SetUpTest(c *gc.C) {
    46  	s.MgoSuite.SetUpTest(c)
    47  	s.BaseSuite.SetUpTest(c)
    48  
    49  	s.Owner = names.NewLocalUserTag("test-admin")
    50  	s.Clock = jujutesting.NewClock(testing.NonZeroTime())
    51  	s.State = InitializeWithArgs(c, InitializeArgs{
    52  		Owner:                     s.Owner,
    53  		InitialConfig:             s.InitialConfig,
    54  		ControllerInheritedConfig: s.ControllerInheritedConfig,
    55  		RegionConfig:              s.RegionConfig,
    56  		NewPolicy:                 s.NewPolicy,
    57  		Clock:                     s.Clock,
    58  	})
    59  	s.AddCleanup(func(*gc.C) { s.State.Close() })
    60  	s.Factory = factory.NewFactory(s.State)
    61  }
    62  
    63  func (s *StateSuite) TearDownTest(c *gc.C) {
    64  	s.BaseSuite.TearDownTest(c)
    65  	s.MgoSuite.TearDownTest(c)
    66  }