github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/instance/namespace_test.go (about)

     1  // Copyright 2016 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package instance_test
     5  
     6  import (
     7  	jc "github.com/juju/testing/checkers"
     8  	gc "gopkg.in/check.v1"
     9  
    10  	"github.com/juju/juju/instance"
    11  )
    12  
    13  type NamespaceSuite struct{}
    14  
    15  var _ = gc.Suite(&NamespaceSuite{})
    16  
    17  const modelUUID = "f47ac10b-58cc-4372-a567-0e02b2c3d479"
    18  
    19  func (s *NamespaceSuite) TestInvalidModelTag(c *gc.C) {
    20  	ns, err := instance.NewNamespace("foo")
    21  	c.Assert(ns, gc.IsNil)
    22  	c.Assert(err, gc.ErrorMatches, `model ID "foo" is not a valid model`)
    23  }
    24  
    25  func (s *NamespaceSuite) newNamespace(c *gc.C) instance.Namespace {
    26  	ns, err := instance.NewNamespace(modelUUID)
    27  	c.Assert(err, jc.ErrorIsNil)
    28  	return ns
    29  }
    30  
    31  func (s *NamespaceSuite) TestInvalidMachineTag(c *gc.C) {
    32  	ns := s.newNamespace(c)
    33  	hostname, err := ns.Hostname("foo")
    34  	c.Assert(hostname, gc.Equals, "")
    35  	c.Assert(err, gc.ErrorMatches, `machine ID "foo" is not a valid machine`)
    36  }
    37  
    38  func (s *NamespaceSuite) TestHostname(c *gc.C) {
    39  	ns := s.newNamespace(c)
    40  	hostname, err := ns.Hostname("2")
    41  	c.Assert(hostname, gc.Equals, "juju-c3d479-2")
    42  	c.Assert(err, jc.ErrorIsNil)
    43  }
    44  
    45  func (s *NamespaceSuite) TestContainerHostname(c *gc.C) {
    46  	ns := s.newNamespace(c)
    47  	hostname, err := ns.Hostname("2/lxd/4")
    48  	c.Assert(hostname, gc.Equals, "juju-c3d479-2-lxd-4")
    49  	c.Assert(err, jc.ErrorIsNil)
    50  }