github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/state/internal_test.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package state
     5  
     6  import (
     7  	"github.com/juju/names"
     8  	jujutesting "github.com/juju/testing"
     9  	jc "github.com/juju/testing/checkers"
    10  	gc "gopkg.in/check.v1"
    11  
    12  	"github.com/juju/juju/mongo"
    13  	"github.com/juju/juju/testing"
    14  )
    15  
    16  var _ = gc.Suite(&internalStateSuite{})
    17  
    18  // internalStateSuite manages a *State instance for tests in the state
    19  // package (i.e. internal tests) that need it. It is similar to
    20  // state.testing.StateSuite but is duplicated to avoid cyclic imports.
    21  type internalStateSuite struct {
    22  	jujutesting.MgoSuite
    23  	testing.BaseSuite
    24  	state *State
    25  	owner names.UserTag
    26  }
    27  
    28  func (s *internalStateSuite) SetUpSuite(c *gc.C) {
    29  	s.MgoSuite.SetUpSuite(c)
    30  	s.BaseSuite.SetUpSuite(c)
    31  }
    32  
    33  func (s *internalStateSuite) TearDownSuite(c *gc.C) {
    34  	s.BaseSuite.TearDownSuite(c)
    35  	s.MgoSuite.TearDownSuite(c)
    36  }
    37  
    38  func (s *internalStateSuite) SetUpTest(c *gc.C) {
    39  	s.MgoSuite.SetUpTest(c)
    40  	s.BaseSuite.SetUpTest(c)
    41  
    42  	s.owner = names.NewLocalUserTag("test-admin")
    43  	// Copied from NewMongoInfo (due to import loops).
    44  	info := &mongo.MongoInfo{
    45  		Info: mongo.Info{
    46  			Addrs:  []string{jujutesting.MgoServer.Addr()},
    47  			CACert: testing.CACert,
    48  		},
    49  	}
    50  	// Copied from NewDialOpts (due to import loops).
    51  	dialopts := mongo.DialOpts{
    52  		Timeout: testing.LongWait,
    53  	}
    54  	st, err := Initialize(s.owner, info, testing.ModelConfig(c), dialopts, nil)
    55  	c.Assert(err, jc.ErrorIsNil)
    56  	s.state = st
    57  	s.AddCleanup(func(*gc.C) { s.state.Close() })
    58  }
    59  
    60  func (s *internalStateSuite) TearDownTest(c *gc.C) {
    61  	s.BaseSuite.TearDownTest(c)
    62  	s.MgoSuite.TearDownTest(c)
    63  }