github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/provider/lxd/instance_test.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  // +build go1.3
     5  
     6  package lxd_test
     7  
     8  import (
     9  	gitjujutesting "github.com/juju/testing"
    10  	jc "github.com/juju/testing/checkers"
    11  	gc "gopkg.in/check.v1"
    12  
    13  	"github.com/juju/juju/instance"
    14  	"github.com/juju/juju/provider/lxd"
    15  	"github.com/juju/juju/tools/lxdclient"
    16  )
    17  
    18  type instanceSuite struct {
    19  	lxd.BaseSuite
    20  }
    21  
    22  var _ = gc.Suite(&instanceSuite{})
    23  
    24  func (s *instanceSuite) TestNewInstance(c *gc.C) {
    25  	inst := lxd.NewInstance(s.RawInstance, s.Env)
    26  
    27  	c.Check(lxd.ExposeInstRaw(inst), gc.Equals, s.RawInstance)
    28  	c.Check(lxd.ExposeInstEnv(inst), gc.Equals, s.Env)
    29  	s.CheckNoAPI(c)
    30  }
    31  
    32  func (s *instanceSuite) TestID(c *gc.C) {
    33  	id := s.Instance.Id()
    34  
    35  	c.Check(id, gc.Equals, instance.Id("spam"))
    36  	s.CheckNoAPI(c)
    37  }
    38  
    39  func (s *instanceSuite) TestStatus(c *gc.C) {
    40  	instanceStatus := s.Instance.Status()
    41  
    42  	c.Check(instanceStatus.Message, gc.Equals, lxdclient.StatusRunning)
    43  	s.CheckNoAPI(c)
    44  }
    45  
    46  func (s *instanceSuite) TestAddresses(c *gc.C) {
    47  	addresses, err := s.Instance.Addresses()
    48  	c.Assert(err, jc.ErrorIsNil)
    49  
    50  	c.Check(addresses, jc.DeepEquals, s.Addresses)
    51  }
    52  
    53  func (s *instanceSuite) TestOpenPortsAPI(c *gc.C) {
    54  	err := s.Instance.OpenPorts("42", s.Ports)
    55  	c.Assert(err, jc.ErrorIsNil)
    56  
    57  	s.Stub.CheckCalls(c, []gitjujutesting.StubCall{{
    58  		FuncName: "OpenPorts",
    59  		Args: []interface{}{
    60  			s.InstName,
    61  			s.Ports,
    62  		},
    63  	}})
    64  }
    65  
    66  func (s *instanceSuite) TestClosePortsAPI(c *gc.C) {
    67  	err := s.Instance.ClosePorts("42", s.Ports)
    68  	c.Assert(err, jc.ErrorIsNil)
    69  
    70  	s.Stub.CheckCalls(c, []gitjujutesting.StubCall{{
    71  		FuncName: "ClosePorts",
    72  		Args: []interface{}{
    73  			s.InstName,
    74  			s.Ports,
    75  		},
    76  	}})
    77  }
    78  
    79  func (s *instanceSuite) TestPortsOkay(c *gc.C) {
    80  	s.Firewaller.PortRanges = s.Ports
    81  
    82  	ports, err := s.Instance.Ports("42")
    83  	c.Assert(err, jc.ErrorIsNil)
    84  
    85  	c.Check(ports, jc.DeepEquals, s.Ports)
    86  }
    87  
    88  func (s *instanceSuite) TestPortsAPI(c *gc.C) {
    89  	_, err := s.Instance.Ports("42")
    90  	c.Assert(err, jc.ErrorIsNil)
    91  
    92  	s.Stub.CheckCalls(c, []gitjujutesting.StubCall{{
    93  		FuncName: "Ports",
    94  		Args: []interface{}{
    95  			s.InstName,
    96  		},
    97  	}})
    98  }