github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/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  	jujutesting "github.com/juju/juju/juju/testing"
    17  	"github.com/juju/juju/mongo"
    18  	coretesting "github.com/juju/juju/testing"
    19  	jujuversion "github.com/juju/juju/version"
    20  )
    21  
    22  func TestAll(t *stdtesting.T) {
    23  	coretesting.MgoTestPackage(t)
    24  }
    25  
    26  type RebootSuite struct {
    27  	jujutesting.JujuConnSuite
    28  
    29  	acfg    agent.Config
    30  	mgoInst testing.MgoInstance
    31  	st      api.Connection
    32  
    33  	tmpDir           string
    34  	rebootScriptName string
    35  }
    36  
    37  var _ = gc.Suite(&RebootSuite{})
    38  
    39  func (s *RebootSuite) SetUpTest(c *gc.C) {
    40  	if testing.GOVERSION < 1.3 {
    41  		c.Skip("skipping test, lxd requires Go 1.3 or later")
    42  	}
    43  
    44  	s.JujuConnSuite.SetUpTest(c)
    45  	testing.PatchExecutableAsEchoArgs(c, s, rebootBin)
    46  	s.PatchEnvironment("TEMP", c.MkDir())
    47  
    48  	s.tmpDir = c.MkDir()
    49  	s.rebootScriptName = "juju-reboot-script"
    50  	s.PatchValue(reboot.TmpFile, func() (*os.File, error) {
    51  		script := s.rebootScript(c)
    52  		return os.Create(script)
    53  	})
    54  
    55  	s.mgoInst.EnableAuth = true
    56  	err := s.mgoInst.Start(coretesting.Certs)
    57  	c.Assert(err, jc.ErrorIsNil)
    58  
    59  	configParams := agent.AgentConfigParams{
    60  		Paths:             agent.Paths{DataDir: c.MkDir()},
    61  		Tag:               names.NewMachineTag("0"),
    62  		UpgradedToVersion: jujuversion.Current,
    63  		StateAddresses:    []string{s.mgoInst.Addr()},
    64  		CACert:            coretesting.CACert,
    65  		Password:          "fake",
    66  		Model:             s.State.ModelTag(),
    67  		MongoVersion:      mongo.Mongo24,
    68  	}
    69  	s.st, _ = s.OpenAPIAsNewMachine(c)
    70  
    71  	s.acfg, err = agent.NewAgentConfig(configParams)
    72  	c.Assert(err, jc.ErrorIsNil)
    73  }
    74  
    75  func (s *RebootSuite) TearDownTest(c *gc.C) {
    76  	s.mgoInst.Destroy()
    77  	s.JujuConnSuite.TearDownTest(c)
    78  }
    79  
    80  func (s *RebootSuite) rebootScript(c *gc.C) string {
    81  	return filepath.Join(s.tmpDir, s.rebootScriptName)
    82  }