github.com/mwhudson/juju@v0.0.0-20160512215208-90ff01f3497f/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/mongo/mongotest" 14 "github.com/juju/juju/testing" 15 ) 16 17 var _ = gc.Suite(&internalStateSuite{}) 18 19 // internalStateSuite manages a *State instance for tests in the state 20 // package (i.e. internal tests) that need it. It is similar to 21 // state.testing.StateSuite but is duplicated to avoid cyclic imports. 22 type internalStateSuite struct { 23 jujutesting.MgoSuite 24 testing.BaseSuite 25 state *State 26 owner names.UserTag 27 } 28 29 func (s *internalStateSuite) SetUpSuite(c *gc.C) { 30 s.MgoSuite.SetUpSuite(c) 31 s.BaseSuite.SetUpSuite(c) 32 } 33 34 func (s *internalStateSuite) TearDownSuite(c *gc.C) { 35 s.BaseSuite.TearDownSuite(c) 36 s.MgoSuite.TearDownSuite(c) 37 } 38 39 func (s *internalStateSuite) SetUpTest(c *gc.C) { 40 s.MgoSuite.SetUpTest(c) 41 s.BaseSuite.SetUpTest(c) 42 43 s.owner = names.NewLocalUserTag("test-admin") 44 // Copied from NewMongoInfo (due to import loops). 45 info := &mongo.MongoInfo{ 46 Info: mongo.Info{ 47 Addrs: []string{jujutesting.MgoServer.Addr()}, 48 CACert: testing.CACert, 49 }, 50 } 51 dialopts := mongotest.DialOpts() 52 st, err := Initialize(s.owner, info, testing.ModelConfig(c), dialopts, nil) 53 c.Assert(err, jc.ErrorIsNil) 54 s.state = st 55 s.AddCleanup(func(*gc.C) { s.state.Close() }) 56 } 57 58 func (s *internalStateSuite) TearDownTest(c *gc.C) { 59 s.BaseSuite.TearDownTest(c) 60 s.MgoSuite.TearDownTest(c) 61 }