Skip to content

Commit

Permalink
Fix the instance tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
howbazaar committed May 31, 2016
1 parent 0b9db62 commit 5b82985
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 5 additions & 1 deletion instance/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import (
"github.com/juju/names"
)

// uuidSuffixDigits defines how many of the uuid digits to use.
// Since the NewNamespace function asserts that the modelUUID is valid, we know
// it follows the UUID string format that ends with eight hex digits.
const uuidSuffixDigits = 6

// Namespace provides a way to generate machine hostanmes with a given prefix.
type Namespace interface {
Expand All @@ -35,7 +39,7 @@ func NewNamespace(modelUUID string) (Namespace, error) {
return nil, errors.Errorf("model ID %q is not a valid model", modelUUID)
}
// The suffix is the last six hex digits of the model uuid.
suffix := modelUUID[len(modelUUID)-6:]
suffix := modelUUID[len(modelUUID)-uuidSuffixDigits:]

return &namespace{name: suffix}, nil
}
Expand Down
9 changes: 4 additions & 5 deletions instance/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
gc "gopkg.in/check.v1"

"github.com/juju/juju/instance"
"github.com/juju/names"
)

type NamespaceSuite struct{}
Expand All @@ -25,26 +24,26 @@ func (s *NamespaceSuite) TestInvalidModelTag(c *gc.C) {

func (s *NamespaceSuite) newNamespace(c *gc.C) instance.Namespace {
ns, err := instance.NewNamespace(modelUUID)
c.Assert(err, jc.ErrIsNil)
c.Assert(err, jc.ErrorIsNil)
return ns
}

func (s *NamespaceSuite) TestInvalidMachineTag(c *gc.C) {
ns := s.newNamespace()
ns := s.newNamespace(c)
hostname, err := ns.Hostname("foo")
c.Assert(hostname, gc.Equals, "")
c.Assert(err, gc.ErrorMatches, `machine ID "foo" is not a valid machine`)
}

func (s *NamespaceSuite) TestHostname(c *gc.C) {
ns := s.newNamespace()
ns := s.newNamespace(c)
hostname, err := ns.Hostname("2")
c.Assert(hostname, gc.Equals, "juju-c3d479-2")
c.Assert(err, jc.ErrorIsNil)
}

func (s *NamespaceSuite) TestContainerHostname(c *gc.C) {
ns := s.newNamespace()
ns := s.newNamespace(c)
hostname, err := ns.Hostname("2/lxd/4")
c.Assert(hostname, gc.Equals, "juju-c3d479-2-lxd-4")
c.Assert(err, jc.ErrorIsNil)
Expand Down

0 comments on commit 5b82985

Please sign in to comment.