github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/cmd/jujud/reboot/reboot_test.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Copyright 2014 Cloudbase Solutions SRL 3 // Licensed under the AGPLv3, see LICENCE file for details. 4 5 package reboot_test 6 7 import ( 8 "os" 9 "path/filepath" 10 stdtesting "testing" 11 12 "github.com/juju/testing" 13 jc "github.com/juju/testing/checkers" 14 gc "gopkg.in/check.v1" 15 "gopkg.in/juju/names.v2" 16 17 "github.com/juju/juju/agent" 18 "github.com/juju/juju/api" 19 "github.com/juju/juju/cmd/jujud/reboot" 20 "github.com/juju/juju/instance" 21 jujutesting "github.com/juju/juju/juju/testing" 22 "github.com/juju/juju/mongo" 23 coretesting "github.com/juju/juju/testing" 24 jujuversion "github.com/juju/juju/version" 25 ) 26 27 func TestAll(t *stdtesting.T) { 28 coretesting.MgoTestPackage(t) 29 } 30 31 type RebootSuite struct { 32 jujutesting.JujuConnSuite 33 34 acfg agent.Config 35 mgoInst testing.MgoInstance 36 st api.Connection 37 38 tmpDir string 39 rebootScriptName string 40 } 41 42 var _ = gc.Suite(&RebootSuite{}) 43 44 func (s *RebootSuite) SetUpSuite(c *gc.C) { 45 s.JujuConnSuite.SetUpSuite(c) 46 47 // These tests only patch out LXC, so only run full-stack tests 48 // over LXC. 49 s.PatchValue(&instance.ContainerTypes, []instance.ContainerType{instance.LXD}) 50 } 51 52 func (s *RebootSuite) SetUpTest(c *gc.C) { 53 54 s.JujuConnSuite.SetUpTest(c) 55 testing.PatchExecutableAsEchoArgs(c, s, rebootBin) 56 s.PatchEnvironment("TEMP", c.MkDir()) 57 58 s.tmpDir = c.MkDir() 59 s.rebootScriptName = "juju-reboot-script" 60 s.PatchValue(reboot.TmpFile, func() (*os.File, error) { 61 script := s.rebootScript(c) 62 return os.Create(script) 63 }) 64 65 s.mgoInst.EnableAuth = true 66 err := s.mgoInst.Start(coretesting.Certs) 67 c.Assert(err, jc.ErrorIsNil) 68 69 configParams := agent.AgentConfigParams{ 70 Paths: agent.Paths{DataDir: c.MkDir()}, 71 Tag: names.NewMachineTag("0"), 72 UpgradedToVersion: jujuversion.Current, 73 StateAddresses: []string{s.mgoInst.Addr()}, 74 CACert: coretesting.CACert, 75 Password: "fake", 76 Controller: s.State.ControllerTag(), 77 Model: s.State.ModelTag(), 78 MongoVersion: mongo.Mongo24, 79 } 80 s.st, _ = s.OpenAPIAsNewMachine(c) 81 82 s.acfg, err = agent.NewAgentConfig(configParams) 83 c.Assert(err, jc.ErrorIsNil) 84 } 85 86 func (s *RebootSuite) TearDownTest(c *gc.C) { 87 s.mgoInst.Destroy() 88 s.JujuConnSuite.TearDownTest(c) 89 } 90 91 func (s *RebootSuite) rebootScript(c *gc.C) string { 92 return filepath.Join(s.tmpDir, s.rebootScriptName) 93 }