github.com/mwhudson/juju@v0.0.0-20160512215208-90ff01f3497f/cmd/jujud/reboot/reboot_test.go (about)

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