當前位置: 首頁>>代碼示例>>Golang>>正文


Golang names.NewSpaceTag函數代碼示例

本文整理匯總了Golang中github.com/juju/names.NewSpaceTag函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewSpaceTag函數的具體用法?Golang NewSpaceTag怎麽用?Golang NewSpaceTag使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewSpaceTag函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的github.com/juju/names.NewSpaceTag函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。