launchpad.net/~rogpeppe/juju-core/500-errgo-fix@v0.0.0-20140213181702-000000002356/names/machine_test.go (about)

     1  // Copyright 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package names_test
     5  
     6  import (
     7  	stdtesting "testing"
     8  
     9  	gc "launchpad.net/gocheck"
    10  
    11  	"launchpad.net/juju-core/names"
    12  )
    13  
    14  type machineSuite struct{}
    15  
    16  var _ = gc.Suite(&machineSuite{})
    17  
    18  func Test(t *stdtesting.T) {
    19  	gc.TestingT(t)
    20  }
    21  
    22  func (s *machineSuite) TestMachineTag(c *gc.C) {
    23  	c.Assert(names.MachineTag("10"), gc.Equals, "machine-10")
    24  	// Check a container id.
    25  	c.Assert(names.MachineTag("10/lxc/1"), gc.Equals, "machine-10-lxc-1")
    26  }
    27  
    28  var machineIdTests = []struct {
    29  	pattern string
    30  	valid   bool
    31  }{
    32  	{pattern: "42", valid: true},
    33  	{pattern: "042", valid: false},
    34  	{pattern: "0", valid: true},
    35  	{pattern: "foo", valid: false},
    36  	{pattern: "/", valid: false},
    37  	{pattern: "55/", valid: false},
    38  	{pattern: "1/foo", valid: false},
    39  	{pattern: "2/foo/", valid: false},
    40  	{pattern: "3/lxc/42", valid: true},
    41  	{pattern: "3/lxc-nodash/42", valid: false},
    42  	{pattern: "0/lxc/00", valid: false},
    43  	{pattern: "0/lxc/0/", valid: false},
    44  	{pattern: "03/lxc/42", valid: false},
    45  	{pattern: "3/lxc/042", valid: false},
    46  	{pattern: "4/foo/bar", valid: false},
    47  	{pattern: "5/lxc/42/foo", valid: false},
    48  	{pattern: "6/lxc/42/kvm/0", valid: true},
    49  	{pattern: "06/lxc/42/kvm/0", valid: false},
    50  	{pattern: "6/lxc/042/kvm/0", valid: false},
    51  	{pattern: "6/lxc/42/kvm/00", valid: false},
    52  	{pattern: "06/lxc/042/kvm/00", valid: false},
    53  }
    54  
    55  func (s *machineSuite) TestMachineIdFormats(c *gc.C) {
    56  	for i, test := range machineIdTests {
    57  		c.Logf("test %d: %q", i, test.pattern)
    58  		c.Assert(names.IsMachine(test.pattern), gc.Equals, test.valid)
    59  	}
    60  }