예제 #1
0
파일: storage_test.go 프로젝트: juju/names
func (s *storageSuite) TestParseStorageTag(c *gc.C) {
	assertParseStorageTag(c, "storage-shared-fs-0", names.NewStorageTag("shared-fs/0"))
	assertParseStorageTag(c, "storage-store-88", names.NewStorageTag("store/88"))
	assertParseStorageTagInvalid(c, "", names.InvalidTagError("", ""))
	assertParseStorageTagInvalid(c, "one", names.InvalidTagError("one", ""))
	assertParseStorageTagInvalid(c, "storage-", names.InvalidTagError("storage-", names.StorageTagKind))
	assertParseStorageTagInvalid(c, "machine-0", names.InvalidTagError("machine-0", names.StorageTagKind))
}
예제 #2
0
func (s *filesystemSuite) TestParseFilesystemTag(c *gc.C) {
	assertParseFilesystemTag(c, "filesystem-0", names.NewFilesystemTag("0"))
	assertParseFilesystemTag(c, "filesystem-88", names.NewFilesystemTag("88"))
	assertParseFilesystemTag(c, "filesystem-0-lxc-0-88", names.NewFilesystemTag("0/lxc/0/88"))
	assertParseFilesystemTagInvalid(c, "", names.InvalidTagError("", ""))
	assertParseFilesystemTagInvalid(c, "one", names.InvalidTagError("one", ""))
	assertParseFilesystemTagInvalid(c, "filesystem-", names.InvalidTagError("filesystem-", names.FilesystemTagKind))
	assertParseFilesystemTagInvalid(c, "machine-0", names.InvalidTagError("machine-0", names.FilesystemTagKind))
}
예제 #3
0
파일: volume_test.go 프로젝트: juju/names
func (s *volumeSuite) TestParseVolumeTag(c *gc.C) {
	assertParseVolumeTag(c, "volume-0", names.NewVolumeTag("0"))
	assertParseVolumeTag(c, "volume-88", names.NewVolumeTag("88"))
	assertParseVolumeTag(c, "volume-0-lxc-0-88", names.NewVolumeTag("0/lxc/0/88"))
	assertParseVolumeTagInvalid(c, "", names.InvalidTagError("", ""))
	assertParseVolumeTagInvalid(c, "one", names.InvalidTagError("one", ""))
	assertParseVolumeTagInvalid(c, "volume-", names.InvalidTagError("volume-", names.VolumeTagKind))
	assertParseVolumeTagInvalid(c, "machine-0", names.InvalidTagError("machine-0", names.VolumeTagKind))
}
예제 #4
0
파일: user_test.go 프로젝트: juju/names
func (s *userSuite) TestParseUserTag(c *gc.C) {
	for i, t := range []struct {
		tag      string
		expected names.Tag
		err      error
	}{{
		tag: "",
		err: names.InvalidTagError("", ""),
	}, {
		tag:      "user-dave",
		expected: names.NewUserTag("dave"),
	}, {
		tag:      "user-dave@local",
		expected: names.NewUserTag("dave@local"),
	}, {
		tag:      "user-dave@foobar",
		expected: names.NewUserTag("dave@foobar"),
	}, {
		tag: "dave",
		err: names.InvalidTagError("dave", ""),
	}, {
		tag: "unit-dave",
		err: names.InvalidTagError("unit-dave", names.UnitTagKind), // not a valid unit name either
	}, {
		tag: "service-dave",
		err: names.InvalidTagError("service-dave", names.UserTagKind),
	}} {
		c.Logf("test %d: %s", i, t.tag)
		got, err := names.ParseUserTag(t.tag)
		if err != nil || t.err != nil {
			c.Check(err, gc.DeepEquals, t.err)
			continue
		}
		c.Check(got, gc.FitsTypeOf, t.expected)
		c.Check(got, gc.Equals, t.expected)
	}
}
예제 #5
0
func (s *actionSuite) TestParseActionTag(c *gc.C) {
	parseActionTagTests := []struct {
		tag      string
		expected names.Tag
		err      error
	}{
		{
			tag:      "",
			expected: nil,
			err:      names.InvalidTagError("", ""),
		}, {
			tag:      "action-good" + names.ActionMarker + "123",
			expected: names.NewActionTag("good" + names.ActionMarker + "123"),
			err:      nil,
		}, {
			tag:      "action-good/0" + names.ActionMarker + "123",
			expected: names.NewActionTag("good/0" + names.ActionMarker + "123"),
			err:      nil,
		}, {
			tag:      "action-bad/00" + names.ActionMarker + "123",
			expected: nil,
			err:      names.InvalidTagError("action-bad/00"+names.ActionMarker+"123", names.ActionTagKind),
		}, {
			tag:      "dave",
			expected: nil,
			err:      names.InvalidTagError("dave", ""),
		}, {
			tag:      "action-dave/0",
			expected: nil,
			err:      names.InvalidTagError("action-dave/0", names.ActionTagKind),
		}, {
			tag:      "action",
			expected: nil,
			err:      names.InvalidTagError("action", ""),
		}, {
			tag:      "user-dave",
			expected: nil,
			err:      names.InvalidTagError("user-dave", names.ActionTagKind),
		}}

	for i, t := range parseActionTagTests {
		c.Logf("test %d: %s", i, t.tag)
		got, err := names.ParseActionTag(t.tag)
		if err != nil || t.err != nil {
			c.Check(err, gc.DeepEquals, t.err)
			continue
		}
		c.Check(got, gc.FitsTypeOf, t.expected)
		c.Check(got, gc.Equals, t.expected)
	}
}
예제 #6
0
			key := peerKey + " " + peerKey
			isValid := testSvc.valid && testRel.valid
			c.Logf("test %d: %q -> valid: %v", i*len(serviceNameTests)+j, key, isValid)
			c.Assert(names.IsValidRelation(key), gc.Equals, isValid)
			c.Assert(names.IsValidRelation(peerKey), gc.Equals, isValid)
		}
	}
}

var parseRelationTagTests = []struct {
	tag      string
	expected names.Tag
	err      error
}{{
	tag: "",
	err: names.InvalidTagError("", ""),
}, {
	tag:      "relation-wordpress:db mysql:db",
	expected: names.NewRelationTag("wordpress:db mysql:db"),
}, {
	tag:      "relation-wordpress:mysql",
	expected: names.NewRelationTag("wordpress:mysql"),
}, {
	tag: "dave",
	err: names.InvalidTagError("dave", ""),
}, {
	tag: "service-dave",
	err: names.InvalidTagError("service-dave", names.RelationTagKind),
}}

func (s *relationSuite) TestParseRelationTag(c *gc.C) {
예제 #7
0
파일: service_test.go 프로젝트: juju/names
		c.Assert(names.IsValidUnit(s+"/"), gc.Equals, false)
	}

	for i, test := range serviceNameTests {
		c.Logf("test %d: %q", i, test.pattern)
		assertService(test.pattern, test.valid)
	}
}

var parseServiceTagTests = []struct {
	tag      string
	expected names.Tag
	err      error
}{{
	tag: "",
	err: names.InvalidTagError("", ""),
}, {
	tag:      "service-dave",
	expected: names.NewServiceTag("dave"),
}, {
	tag: "dave",
	err: names.InvalidTagError("dave", ""),
}, {
	tag: "service-dave/0",
	err: names.InvalidTagError("service-dave/0", names.ServiceTagKind),
}, {
	tag: "service",
	err: names.InvalidTagError("service", ""),
}, {
	tag: "user-dave",
	err: names.InvalidTagError("user-dave", names.ServiceTagKind),
예제 #8
0
파일: subnet_test.go 프로젝트: juju/names
	c.Assert(parsed.Id(), gc.Equals, cidr)
	c.Assert(parsed.String(), gc.Equals, names.SubnetTagKind+"-"+cidr)

	f := func() {
		tag = names.NewSubnetTag("foo")
	}
	c.Assert(f, gc.PanicMatches, "foo is not a valid subnet CIDR")
}

var parseSubnetTagTests = []struct {
	tag      string
	expected names.Tag
	err      error
}{{
	tag: "",
	err: names.InvalidTagError("", ""),
}, {
	tag:      "subnet-10.20.0.0/16",
	expected: names.NewSubnetTag("10.20.0.0/16"),
}, {
	tag:      "subnet-2001:db8::/32",
	expected: names.NewSubnetTag("2001:db8::/32"),
}, {
	tag: "subnet-fe80::3%zone1/10",
	err: names.InvalidTagError("subnet-fe80::3%zone1/10", names.SubnetTagKind),
}, {
	tag: "subnet-10.20.30.40/16",
	err: names.InvalidTagError("subnet-10.20.30.40/16", names.SubnetTagKind),
}, {
	tag: "subnet-2001:db8::123/32",
	err: names.InvalidTagError("subnet-2001:db8::123/32", names.SubnetTagKind),
예제 #9
0
파일: action_test.go 프로젝트: makyo/names
import (
	gc "gopkg.in/check.v1"

	"github.com/juju/names"
)

type actionSuite struct{}

var _ = gc.Suite(&actionSuite{})

var parseActionTagTests = []struct {
	tag      string
	expected names.Tag
	err      error
}{
	{tag: "", err: names.InvalidTagError("", "")},
	{tag: "action-f47ac10b-58cc-4372-a567-0e02b2c3d479", expected: names.NewActionTag("f47ac10b-58cc-4372-a567-0e02b2c3d479")},
	{tag: "action-012345678", err: names.InvalidTagError("action-012345678", "action")},
	{tag: "action-1234567", err: names.InvalidTagError("action-1234567", "action")},
	{tag: "bob", err: names.InvalidTagError("bob", "")},
	{tag: "service-ned", err: names.InvalidTagError("service-ned", names.ActionTagKind)}}

func (s *actionSuite) TestParseActionTag(c *gc.C) {
	for i, t := range parseActionTagTests {
		c.Logf("test %d: %s", i, t.tag)
		got, err := names.ParseActionTag(t.tag)
		if err != nil || t.err != nil {
			c.Check(err, gc.DeepEquals, t.err)
			continue
		}
		c.Check(got, gc.FitsTypeOf, t.expected)
예제 #10
0
파일: environ_test.go 프로젝트: juju/names
	gc "gopkg.in/check.v1"

	"github.com/juju/names"
)

type environSuite struct{}

var _ = gc.Suite(&environSuite{})

var parseEnvironTagTests = []struct {
	tag      string
	expected names.Tag
	err      error
}{{
	tag: "",
	err: names.InvalidTagError("", ""),
}, {
	tag:      "environment-f47ac10b-58cc-4372-a567-0e02b2c3d479",
	expected: names.NewEnvironTag("f47ac10b-58cc-4372-a567-0e02b2c3d479"),
}, {
	tag: "dave",
	err: names.InvalidTagError("dave", ""),
	//}, {
	// TODO(dfc) passes, but should not
	//	tag: "environment-",
	//	err: names.InvalidTagError("environment", ""),
}, {
	tag: "service-dave",
	err: names.InvalidTagError("service-dave", names.EnvironTagKind),
}}
예제 #11
0
파일: machine_test.go 프로젝트: makyo/names
func (s *machineSuite) TestMachineIdFormats(c *gc.C) {
	for i, test := range machineIdTests {
		c.Logf("test %d: %q", i, test.pattern)
		c.Assert(names.IsValidMachine(test.pattern), gc.Equals, test.valid)
		c.Assert(names.IsContainerMachine(test.pattern), gc.Equals, test.container)
	}
}

var parseMachineTagTests = []struct {
	tag      string
	expected names.Tag
	err      error
}{{
	tag: "",
	err: names.InvalidTagError("", ""),
}, {
	tag:      "machine-0",
	expected: names.NewMachineTag("0"),
}, {
	tag: "machine-one",
	err: names.InvalidTagError("machine-one", names.MachineTagKind),
}, {
	tag: "dave",
	err: names.InvalidTagError("dave", ""),
}, {
	tag: "user-one",
	err: names.InvalidTagError("user-one", names.MachineTagKind),
}}

func (s *machineSuite) TestParseMachineTag(c *gc.C) {
예제 #12
0
			c.Check(names.NewNetworkTag(test.pattern).String(), gc.Equals, expectTag)
		} else {
			expectErr := fmt.Sprintf("%q is not a valid network name", test.pattern)
			testNetworkTag := func() { names.NewNetworkTag(test.pattern) }
			c.Check(testNetworkTag, gc.PanicMatches, regexp.QuoteMeta(expectErr))
		}
	}
}

var parseNetworkTagTests = []struct {
	tag      string
	expected names.Tag
	err      error
}{{
	tag: "",
	err: names.InvalidTagError("", ""),
}, {
	tag:      "network-dave",
	expected: names.NewNetworkTag("dave"),
}, {
	tag: "dave",
	err: names.InvalidTagError("dave", ""),
}, {
	tag: "network-dave/0",
	err: names.InvalidTagError("network-dave/0", names.NetworkTagKind),
}, {
	tag: "network",
	err: names.InvalidTagError("network", ""),
}, {
	tag: "user-dave",
	err: names.InvalidTagError("user-dave", names.NetworkTagKind),
예제 #13
0
		{"bar@", false},
		{"@local", false},
		{"not/valid", false},
	} {
		c.Logf("test %d: %s", i, t.string)
		c.Assert(names.IsValidUserName(t.string), gc.Equals, t.expect, gc.Commentf("%s", t.string))
	}
}

var parseUserTagTests = []struct {
	tag      string
	expected names.Tag
	err      error
}{{
	tag: "",
	err: names.InvalidTagError("", ""),
}, {
	tag:      "user-dave",
	expected: names.NewUserTag("dave"),
}, {
	tag:      "user-dave@local",
	expected: names.NewUserTag("dave@local"),
}, {
	tag:      "user-dave@foobar",
	expected: names.NewUserTag("dave@foobar"),
}, {
	tag: "dave",
	err: names.InvalidTagError("dave", ""),
}, {
	tag: "unit-dave",
	err: names.InvalidTagError("unit-dave", names.UnitTagKind), // not a valid unit name either
예제 #14
0
	c.Assert(parsed.Kind(), gc.Equals, names.IPAddressTagKind)
	c.Assert(parsed.Id(), gc.Equals, uuid.String())
	c.Assert(parsed.String(), gc.Equals, names.IPAddressTagKind+"-"+uuid.String())

	f := func() {
		tag = names.NewIPAddressTag("42")
	}
	c.Assert(f, gc.PanicMatches, `invalid UUID: "42"`)
}

var parseIPAddressTagTests = []struct {
	tag      string
	expected names.Tag
	err      error
}{
	{tag: "", err: names.InvalidTagError("", "")},
	{tag: "ipaddress-42424242-1111-2222-3333-0123456789ab", expected: names.NewIPAddressTag("42424242-1111-2222-3333-0123456789ab")},
	{tag: "ipaddress-012345678", err: names.InvalidTagError("ipaddress-012345678", names.IPAddressTagKind)},
	{tag: "ipaddress-42", err: names.InvalidTagError("ipaddress-42", names.IPAddressTagKind)},
	{tag: "foobar", err: names.InvalidTagError("foobar", "")},
	{tag: "space-yadda", err: names.InvalidTagError("space-yadda", names.IPAddressTagKind)}}

func (s *ipAddressSuite) TestParseIPAddressTag(c *gc.C) {
	for i, t := range parseIPAddressTagTests {
		c.Logf("test %d: %s", i, t.tag)
		got, err := names.ParseIPAddressTag(t.tag)
		if err != nil || t.err != nil {
			c.Check(err, gc.DeepEquals, t.err)
			continue
		}
		c.Check(got, gc.FitsTypeOf, t.expected)
예제 #15
0
파일: space_test.go 프로젝트: makyo/names
			c.Check(names.NewSpaceTag(test.pattern).String(), gc.Equals, expectTag)
		} else {
			expectErr := fmt.Sprintf("%q is not a valid space name", test.pattern)
			testTag := func() { names.NewSpaceTag(test.pattern) }
			c.Check(testTag, gc.PanicMatches, regexp.QuoteMeta(expectErr))
		}
	}
}

var parseSpaceTagTests = []struct {
	tag      string
	expected names.Tag
	err      error
}{{
	tag: "",
	err: names.InvalidTagError("", ""),
}, {
	tag:      "space-1",
	expected: names.NewSpaceTag("1"),
}, {
	tag: "-space1",
	err: names.InvalidTagError("-space1", ""),
}}

func (s *spaceSuite) TestParseSpaceTag(c *gc.C) {
	for i, t := range parseSpaceTagTests {
		c.Logf("test %d: %s", i, t.tag)
		got, err := names.ParseSpaceTag(t.tag)
		if err != nil || t.err != nil {
			c.Check(err, gc.DeepEquals, t.err)
			continue
예제 #16
0
	}

	for i, test := range actionNameTests {
		c.Logf("test %d: %q", i, test.pattern)
		assertAction(test.pattern, test.valid)
	}
}

var parseActionTagTests = []struct {
	tag      string
	expected names.Tag
	err      error
}{{
	tag:      "",
	expected: nil,
	err:      names.InvalidTagError("", ""),
}, {
	tag:      "action-dave" + names.ActionMarker + "123",
	expected: names.NewActionTag("dave" + names.ActionMarker + "123"),
	err:      nil,
}, {
	tag:      "dave",
	expected: nil,
	err:      names.InvalidTagError("dave", ""),
}, {
	tag:      "action-dave/0",
	expected: nil,
	err:      names.InvalidTagError("action-dave/0", names.ActionTagKind),
}, {
	tag:      "action",
	expected: nil,