本文整理匯總了Golang中github.com/juju/names.InvalidTagError函數的典型用法代碼示例。如果您正苦於以下問題:Golang InvalidTagError函數的具體用法?Golang InvalidTagError怎麽用?Golang InvalidTagError使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了InvalidTagError函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestParseStorageTag
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: TestParseFilesystemTag
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: TestParseVolumeTag
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: TestParseUserTag
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: "[email protected]",
expected: names.NewUserTag("[email protected]"),
}, {
tag: "[email protected]",
expected: names.NewUserTag("[email protected]"),
}, {
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: TestParseActionTag
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: TestParseRelationTag
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:
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:
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: TestParseActionTag
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:
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: TestMachineIdFormats
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:
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:
{"[email protected]", 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: "[email protected]",
expected: names.NewUserTag("[email protected]"),
}, {
tag: "[email protected]",
expected: names.NewUserTag("[email protected]"),
}, {
tag: "dave",
err: names.InvalidTagError("dave", ""),
}, {
tag: "unit-dave",
err: names.InvalidTagError("unit-dave", names.UnitTagKind), // not a valid unit name either
示例14: TestParseIPAddressTag
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: TestParseSpaceTag
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