本文整理汇总了Golang中github.com/juju/names.NewSpaceTag函数的典型用法代码示例。如果您正苦于以下问题:Golang NewSpaceTag函数的具体用法?Golang NewSpaceTag怎么用?Golang NewSpaceTag使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewSpaceTag函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestRunWithFilteringSucceeds
func (s *ListSuite) TestRunWithFilteringSucceeds(c *gc.C) {
// Simulate one subnet is using the "public" space or "zone1".
s.api.Subnets = s.api.Subnets[0:1]
expected := `
subnets:
10.20.0.0/24:
type: ipv4
provider-id: subnet-foo
status: in-use
space: public
zones:
- zone1
- zone2
`[1:]
// Filter by space name first.
s.AssertRunSucceeds(c,
"", // empty stderr.
expected,
"--space", "public",
)
s.api.CheckCallNames(c, "ListSubnets", "Close")
tag := names.NewSpaceTag("public")
s.api.CheckCall(c, 0, "ListSubnets", &tag, "")
s.api.ResetCalls()
// Now filter by zone.
s.AssertRunSucceeds(c,
"", // empty stderr.
expected,
"--zone", "zone1",
)
s.api.CheckCallNames(c, "ListSubnets", "Close")
s.api.CheckCall(c, 0, "ListSubnets", nil, "zone1")
s.api.ResetCalls()
// Finally, filter by both space and zone.
s.AssertRunSucceeds(c,
"", // empty stderr.
expected,
"--zone", "zone1", "--space", "public",
)
s.api.CheckCallNames(c, "ListSubnets", "Close")
tag = names.NewSpaceTag("public")
s.api.CheckCall(c, 0, "ListSubnets", &tag, "zone1")
}
开发者ID:makyo,项目名称:juju,代码行数:50,代码来源:list_test.go
示例2: TestSpaceNames
func (s *spaceSuite) TestSpaceNames(c *gc.C) {
for i, test := range spaceNameTests {
c.Logf("test %d: %q", i, test.pattern)
c.Check(names.IsValidSpace(test.pattern), gc.Equals, test.valid)
if test.valid {
expectTag := fmt.Sprintf("%s-%s", names.SpaceTagKind, test.pattern)
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))
}
}
}
开发者ID:makyo,项目名称:names,代码行数:14,代码来源:space_test.go
示例3: makeCreateSubnetsArgs
func makeCreateSubnetsArgs(cidr, space string, zones []string, isPublic bool) apitesting.CheckArgs {
spaceTag := names.NewSpaceTag(space).String()
subnetTag := names.NewSubnetTag(cidr).String()
expectArgs := params.CreateSubnetsParams{
Subnets: []params.CreateSubnetParams{{
SpaceTag: spaceTag,
SubnetTag: subnetTag,
Zones: zones,
IsPublic: isPublic,
}}}
expectResults := params.ErrorResults{
Results: []params.ErrorResult{{}},
}
args := apitesting.CheckArgs{
Facade: "Subnets",
Method: "CreateSubnets",
Args: expectArgs,
Results: expectResults,
}
return args
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:25,代码来源:subnets_test.go
示例4: makeArgs
func makeArgs(name string, subnets []string) (string, []string, apitesting.CheckArgs) {
spaceTag := names.NewSpaceTag(name).String()
subnetTags := []string{}
for _, s := range subnets {
subnetTags = append(subnetTags, names.NewSubnetTag(s).String())
}
expectArgs := params.CreateSpacesParams{
Spaces: []params.CreateSpaceParams{
params.CreateSpaceParams{
SpaceTag: spaceTag,
SubnetTags: subnetTags,
Public: true,
}}}
expectResults := params.ErrorResults{
Results: []params.ErrorResult{{}},
}
args := apitesting.CheckArgs{
Facade: "Spaces",
Method: "CreateSpaces",
Args: expectArgs,
Results: expectResults,
}
return name, subnets, args
}
开发者ID:imoapps,项目名称:juju,代码行数:29,代码来源:spaces_test.go
示例5: TestWorkerIgnoresExistingSpacesAndSubnets
func (s *WorkerSuite) TestWorkerIgnoresExistingSpacesAndSubnets(c *gc.C) {
dummy.SetSupportsSpaceDiscovery(true)
spaceTag := names.NewSpaceTag("foo")
args := params.CreateSpacesParams{
Spaces: []params.CreateSpaceParams{{
Public: false,
SpaceTag: spaceTag.String(),
ProviderId: "foo",
}}}
result, err := s.API.CreateSpaces(args)
c.Assert(err, jc.ErrorIsNil)
c.Assert(result.Results, gc.HasLen, 1)
c.Assert(result.Results[0].Error, gc.IsNil)
subnetArgs := params.AddSubnetsParams{
Subnets: []params.AddSubnetParams{{
SubnetProviderId: "1",
SpaceTag: spaceTag.String(),
Zones: []string{"zone1"},
}}}
subnetResult, err := s.API.AddSubnets(subnetArgs)
c.Assert(err, jc.ErrorIsNil)
c.Assert(subnetResult.Results, gc.HasLen, 1)
c.Assert(subnetResult.Results[0].Error, gc.IsNil)
s.unlockCheck(c, func(c *gc.C) {
spaces, err := s.State.AllSpaces()
c.Assert(err, jc.ErrorIsNil)
c.Assert(spaces, gc.HasLen, 5)
})
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:31,代码来源:worker_test.go
示例6: makeAddSubnetsArgs
func makeAddSubnetsArgs(cidr, providerId, space string, zones []string) apitesting.CheckArgs {
spaceTag := names.NewSpaceTag(space).String()
subnetTag := names.NewSubnetTag(cidr).String()
if providerId != "" {
subnetTag = ""
}
expectArgs := params.AddSubnetsParams{
Subnets: []params.AddSubnetParams{{
SpaceTag: spaceTag,
SubnetTag: subnetTag,
SubnetProviderId: providerId,
Zones: zones,
}}}
expectResults := params.ErrorResults{
Results: []params.ErrorResult{{}},
}
args := apitesting.CheckArgs{
Facade: "Subnets",
Method: "AddSubnets",
Args: expectArgs,
Results: expectResults,
}
return args
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:28,代码来源:subnets_test.go
示例7: TestAuthFuncForTagKind
func (s *commonSuite) TestAuthFuncForTagKind(c *gc.C) {
// TODO(dimitern): This list of all supported tags and kinds needs
// to live in juju/names.
uuid, err := utils.NewUUID()
c.Assert(err, jc.ErrorIsNil)
allTags := []names.Tag{
nil, // invalid tag
names.NewActionTag(uuid.String()),
names.NewCharmTag("cs:precise/missing"),
names.NewModelTag(uuid.String()),
names.NewFilesystemTag("20/20"),
names.NewLocalUserTag("user"),
names.NewMachineTag("42"),
names.NewNetworkTag("public"),
names.NewRelationTag("wordpress:mysql mysql:db"),
names.NewServiceTag("wordpress"),
names.NewSpaceTag("apps"),
names.NewStorageTag("foo/42"),
names.NewUnitTag("wordpress/5"),
names.NewUserTag("joe"),
names.NewVolumeTag("80/20"),
}
for i, allowedTag := range allTags {
c.Logf("test #%d: allowedTag: %v", i, allowedTag)
var allowedKind string
if allowedTag != nil {
allowedKind = allowedTag.Kind()
}
getAuthFunc := common.AuthFuncForTagKind(allowedKind)
authFunc, err := getAuthFunc()
if allowedKind == "" {
c.Check(err, gc.ErrorMatches, "tag kind cannot be empty")
c.Check(authFunc, gc.IsNil)
continue
} else if !c.Check(err, jc.ErrorIsNil) {
continue
}
for j, givenTag := range allTags {
c.Logf("test #%d.%d: givenTag: %v", i, j, givenTag)
var givenKind string
if givenTag != nil {
givenKind = givenTag.Kind()
}
if allowedKind == givenKind {
c.Check(authFunc(givenTag), jc.IsTrue)
} else {
c.Check(authFunc(givenTag), jc.IsFalse)
}
}
}
}
开发者ID:exekias,项目名称:juju,代码行数:56,代码来源:common_test.go
示例8: TestRunOneZoneSucceeds
func (s *CreateSuite) TestRunOneZoneSucceeds(c *gc.C) {
s.AssertRunSucceeds(c,
`created a private subnet "10.20.0.0/24" in space "myspace" with zones zone1\n`,
"", // empty stdout.
"10.20.0.0/24", "myspace", "zone1",
)
s.api.CheckCallNames(c, "AllZones", "CreateSubnet", "Close")
s.api.CheckCall(c, 1, "CreateSubnet",
names.NewSubnetTag("10.20.0.0/24"), names.NewSpaceTag("myspace"), s.Strings("zone1"), false,
)
}
开发者ID:pmatulis,项目名称:juju,代码行数:12,代码来源:create_test.go
示例9: TestRunWithPublicAndIPv6CIDRSucceeds
func (s *CreateSuite) TestRunWithPublicAndIPv6CIDRSucceeds(c *gc.C) {
s.AssertRunSucceeds(c,
`created a public subnet "2001:db8::/32" in space "space" with zones zone1\n`,
"", // empty stdout.
"2001:db8::/32", "space", "zone1", "--public",
)
s.api.CheckCallNames(c, "AllZones", "CreateSubnet", "Close")
s.api.CheckCall(c, 1, "CreateSubnet",
names.NewSubnetTag("2001:db8::/32"), names.NewSpaceTag("space"), s.Strings("zone1"), true,
)
}
开发者ID:pmatulis,项目名称:juju,代码行数:12,代码来源:create_test.go
示例10: TestListSubnetsFails
func (s *SubnetsSuite) TestListSubnetsFails(c *gc.C) {
space := names.NewSpaceTag("foo")
zone := "bar"
args := makeListSubnetsArgs(&space, zone)
s.prepareAPICall(c, &args, errors.New("bang"))
results, err := s.api.ListSubnets(&space, zone)
c.Assert(s.called, gc.Equals, 1)
c.Assert(err, gc.ErrorMatches, "bang")
var expectedResults []params.Subnet
c.Assert(results, jc.DeepEquals, expectedResults)
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:12,代码来源:subnets_test.go
示例11: TestRunWithExistingSubnetFails
func (s *CreateSuite) TestRunWithExistingSubnetFails(c *gc.C) {
s.api.SetErrors(nil, errors.AlreadyExistsf("subnet %q", "10.10.0.0/24"))
err := s.AssertRunFails(c,
`cannot create subnet "10.10.0.0/24": subnet "10.10.0.0/24" already exists`,
"10.10.0.0/24", "space", "zone1",
)
c.Assert(err, jc.Satisfies, errors.IsAlreadyExists)
s.api.CheckCallNames(c, "AllZones", "CreateSubnet", "Close")
s.api.CheckCall(c, 1, "CreateSubnet",
names.NewSubnetTag("10.10.0.0/24"), names.NewSpaceTag("space"), s.Strings("zone1"), false,
)
}
开发者ID:pmatulis,项目名称:juju,代码行数:14,代码来源:create_test.go
示例12: makeCreateSpaceParams
func makeCreateSpaceParams(name string, subnetIds []string, public bool) params.CreateSpaceParams {
spaceTag := names.NewSpaceTag(name).String()
subnetTags := make([]string, len(subnetIds))
for i, s := range subnetIds {
subnetTags[i] = names.NewSubnetTag(s).String()
}
return params.CreateSpaceParams{
SpaceTag: spaceTag,
SubnetTags: subnetTags,
Public: public,
}
}
开发者ID:imoapps,项目名称:juju,代码行数:14,代码来源:spaces.go
示例13: AssertAllSpacesResult
// AssertAllSpacesResult makes it easier to verify AllSpaces results.
func (s *SubnetsSuite) AssertAllSpacesResult(c *gc.C, got params.SpaceResults, expected []common.BackingSpace) {
seen := set.Strings{}
results := []params.SpaceResult{}
for _, space := range expected {
if seen.Contains(space.Name()) {
continue
}
seen.Add(space.Name())
result := params.SpaceResult{}
result.Tag = names.NewSpaceTag(space.Name()).String()
results = append(results, result)
}
c.Assert(got, jc.DeepEquals, params.SpaceResults{Results: results})
}
开发者ID:mhilton,项目名称:juju,代码行数:15,代码来源:subnets_test.go
示例14: TestRunWhenNoneMatchSucceeds
func (s *ListSuite) TestRunWhenNoneMatchSucceeds(c *gc.C) {
// Simulate no subnets are using the "default" space.
s.api.Subnets = s.api.Subnets[0:0]
s.AssertRunSucceeds(c,
`no subnets found matching requested criteria\n`,
"", // empty stdout.
"--space", "default",
)
s.api.CheckCallNames(c, "ListSubnets", "Close")
tag := names.NewSpaceTag("default")
s.api.CheckCall(c, 0, "ListSubnets", &tag, "")
}
开发者ID:makyo,项目名称:juju,代码行数:14,代码来源:list_test.go
示例15: TestRunWithMultipleZonesSucceeds
func (s *CreateSuite) TestRunWithMultipleZonesSucceeds(c *gc.C) {
s.AssertRunSucceeds(c,
// The list of zones is sorted both when displayed and passed
// to CreateSubnet.
`created a private subnet "10.20.0.0/24" in space "foo" with zones zone1, zone2\n`,
"", // empty stdout.
"10.20.0.0/24", "foo", "zone2", "zone1", // unsorted zones
)
s.api.CheckCallNames(c, "AllZones", "CreateSubnet", "Close")
s.api.CheckCall(c, 1, "CreateSubnet",
names.NewSubnetTag("10.20.0.0/24"), names.NewSpaceTag("foo"), s.Strings("zone1", "zone2"), false,
)
}
开发者ID:pmatulis,项目名称:juju,代码行数:14,代码来源:create_test.go
示例16: TestRunWithNonExistingSpaceFails
func (s *CreateSuite) TestRunWithNonExistingSpaceFails(c *gc.C) {
s.api.SetErrors(nil, errors.NotFoundf("space %q", "space"))
err := s.AssertRunFails(c,
`cannot create subnet "10.10.0.0/24": space "space" not found`,
"10.10.0.0/24", "space", "zone1",
)
c.Assert(err, jc.Satisfies, errors.IsNotFound)
s.api.CheckCallNames(c, "AllZones", "CreateSubnet", "Close")
s.api.CheckCall(c, 1, "CreateSubnet",
names.NewSubnetTag("10.10.0.0/24"), names.NewSpaceTag("space"), s.Strings("zone1"), false,
)
}
开发者ID:pmatulis,项目名称:juju,代码行数:14,代码来源:create_test.go
示例17: NewStubAPI
// NewStubAPI creates a StubAPI suitable for passing to
// subnet.New*Command().
func NewStubAPI() *StubAPI {
subnets := []params.Subnet{{
// IPv4 subnet.
CIDR: "10.20.0.0/24",
ProviderId: "subnet-foo",
Life: params.Alive,
SpaceTag: "space-public",
Zones: []string{"zone1", "zone2"},
StaticRangeLowIP: net.ParseIP("10.20.0.10"),
StaticRangeHighIP: net.ParseIP("10.20.0.100"),
}, {
// IPv6 subnet.
CIDR: "2001:db8::/32",
ProviderId: "subnet-bar",
Life: params.Dying,
SpaceTag: "space-dmz",
Zones: []string{"zone2"},
}, {
// IPv4 VLAN subnet.
CIDR: "10.10.0.0/16",
Life: params.Dead,
SpaceTag: "space-vlan-42",
Zones: []string{"zone1"},
VLANTag: 42,
}}
return &StubAPI{
Stub: &testing.Stub{},
Zones: []string{"zone1", "zone2"},
Subnets: subnets,
Spaces: []names.Tag{
names.NewSpaceTag("default"),
names.NewSpaceTag("public"),
names.NewSpaceTag("dmz"),
names.NewSpaceTag("vlan-42"),
},
}
}
开发者ID:exekias,项目名称:juju,代码行数:39,代码来源:package_test.go
示例18: TestRunWithIPv6CIDRSucceeds
func (s *AddSuite) TestRunWithIPv6CIDRSucceeds(c *gc.C) {
s.AssertRunSucceeds(c,
`added subnet with CIDR "2001:db8::/32" in space "hyperspace"\n`,
"", // empty stdout.
"2001:db8::/32", "hyperspace",
)
s.api.CheckCallNames(c, "AddSubnet", "Close")
s.api.CheckCall(c, 0, "AddSubnet",
names.NewSubnetTag("2001:db8::/32"),
network.Id(""),
names.NewSpaceTag("hyperspace"),
[]string(nil),
)
}
开发者ID:makyo,项目名称:juju,代码行数:15,代码来源:add_test.go
示例19: TestRunWithProviderIdSucceeds
func (s *AddSuite) TestRunWithProviderIdSucceeds(c *gc.C) {
s.AssertRunSucceeds(c,
`added subnet with ProviderId "foo" in space "myspace"\n`,
"", // empty stdout.
"foo", "myspace", "zone1", "zone2",
)
s.api.CheckCallNames(c, "AddSubnet", "Close")
s.api.CheckCall(c, 0, "AddSubnet",
names.SubnetTag{},
network.Id("foo"),
names.NewSpaceTag("myspace"),
s.Strings("zone1", "zone2"),
)
}
开发者ID:makyo,项目名称:juju,代码行数:15,代码来源:add_test.go
示例20: TestRunWithIPv4CIDRSucceeds
func (s *AddSuite) TestRunWithIPv4CIDRSucceeds(c *gc.C) {
s.AssertRunSucceeds(c,
`added subnet with CIDR "10.20.0.0/24" in space "myspace"\n`,
"", // empty stdout.
"10.20.0.0/24", "myspace",
)
s.api.CheckCallNames(c, "AddSubnet", "Close")
s.api.CheckCall(c, 0, "AddSubnet",
names.NewSubnetTag("10.20.0.0/24"),
network.Id(""),
names.NewSpaceTag("myspace"),
[]string(nil),
)
}
开发者ID:makyo,项目名称:juju,代码行数:15,代码来源:add_test.go
注:本文中的github.com/juju/names.NewSpaceTag函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论