当前位置: 首页>>代码示例>>Golang>>正文


Golang set.NewTags函数代码示例

本文整理汇总了Golang中github.com/juju/utils/set.NewTags函数的典型用法代码示例。如果您正苦于以下问题:Golang NewTags函数的具体用法?Golang NewTags怎么用?Golang NewTags使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewTags函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestDifference

func (s tagSetSuite) TestDifference(c *gc.C) {
	t1 := set.NewTags(s.foo, s.bar)
	t2 := set.NewTags(s.foo, s.baz, s.bang)

	diff1 := t1.Difference(t2)
	diff2 := t2.Difference(t1)

	c.Assert(diff1, gc.DeepEquals, set.NewTags(s.bar))
	c.Assert(diff2, gc.DeepEquals, set.NewTags(s.baz, s.bang))
}
开发者ID:anastasiamac,项目名称:utils,代码行数:10,代码来源:tags_test.go

示例2: MinionReports

// MinionReports implements ModelMigration.
func (mig *modelMigration) MinionReports() (*MinionReports, error) {
	all, err := mig.getAllAgents()
	if err != nil {
		return nil, errors.Trace(err)
	}

	phase, err := mig.Phase()
	if err != nil {
		return nil, errors.Annotate(err, "retrieving phase")
	}

	coll, closer := mig.st.getCollection(migrationsMinionSyncC)
	defer closer()
	query := coll.Find(bson.M{"_id": bson.M{
		"$regex": "^" + mig.minionReportId(phase, ".+"),
	}})
	query = query.Select(bson.M{
		"entity-key": 1,
		"success":    1,
	})
	var docs []bson.M
	if err := query.All(&docs); err != nil {
		return nil, errors.Annotate(err, "retrieving minion reports")
	}

	succeeded := set.NewTags()
	failed := set.NewTags()
	for _, doc := range docs {
		entityKey, ok := doc["entity-key"].(string)
		if !ok {
			return nil, errors.Errorf("unexpected entity-key %v", doc["entity-key"])
		}
		tag, err := globalKeyToAgentTag(entityKey)
		if err != nil {
			return nil, errors.Trace(err)
		}
		success, ok := doc["success"].(bool)
		if !ok {
			return nil, errors.Errorf("unexpected success value: %v", doc["success"])
		}
		if success {
			succeeded.Add(tag)
		} else {
			failed.Add(tag)
		}
	}

	unknown := all.Difference(succeeded).Difference(failed)

	return &MinionReports{
		Succeeded: succeeded.Values(),
		Failed:    failed.Values(),
		Unknown:   unknown.Values(),
	}, nil
}
开发者ID:bac,项目名称:juju,代码行数:56,代码来源:modelmigration.go

示例3: TestUnion

func (s tagSetSuite) TestUnion(c *gc.C) {
	t1 := set.NewTags(s.foo, s.bar)
	t2 := set.NewTags(s.foo, s.baz, s.bang)
	union1 := t1.Union(t2)
	union2 := t2.Union(t1)

	c.Assert(union1.Size(), gc.Equals, 4)
	c.Assert(union2.Size(), gc.Equals, 4)

	c.Assert(union1, gc.DeepEquals, union2)
	c.Assert(union1, gc.DeepEquals, set.NewTags(s.foo, s.bar, s.baz, s.bang))
}
开发者ID:anastasiamac,项目名称:utils,代码行数:12,代码来源:tags_test.go

示例4: TestIsEmpty

func (s tagSetSuite) TestIsEmpty(c *gc.C) {
	// Empty sets are empty.
	t := set.NewTags()
	c.Assert(t.IsEmpty(), gc.Equals, true)

	// Non-empty sets are not empty.
	t = set.NewTags(s.foo)
	c.Assert(t.IsEmpty(), gc.Equals, false)

	// Newly empty sets work too.
	t.Remove(s.foo)
	c.Assert(t.IsEmpty(), gc.Equals, true)
}
开发者ID:anastasiamac,项目名称:utils,代码行数:13,代码来源:tags_test.go

示例5: TestIntersection

func (s tagSetSuite) TestIntersection(c *gc.C) {
	t1 := set.NewTags(s.foo, s.bar)
	t2 := set.NewTags(s.foo, s.baz, s.bang)

	int1 := t1.Intersection(t2)
	int2 := t2.Intersection(t1)

	c.Assert(int1.Size(), gc.Equals, 1)
	c.Assert(int2.Size(), gc.Equals, 1)

	c.Assert(int1, gc.DeepEquals, int2)
	c.Assert(int1, gc.DeepEquals, set.NewTags(s.foo))
}
开发者ID:anastasiamac,项目名称:utils,代码行数:13,代码来源:tags_test.go

示例6: TestRemove

func (s tagSetSuite) TestRemove(c *gc.C) {
	t := set.NewTags(s.foo, s.bar)
	t.Remove(s.foo)

	c.Assert(t.Contains(s.foo), gc.Equals, false)
	c.Assert(t.Contains(s.bar), gc.Equals, true)
}
开发者ID:anastasiamac,项目名称:utils,代码行数:7,代码来源:tags_test.go

示例7: TestAddDuplicate

func (s tagSetSuite) TestAddDuplicate(c *gc.C) {
	t := set.NewTags()

	t.Add(s.foo)
	t.Add(s.bar)
	t.Add(s.bar)

	c.Assert(t.Size(), gc.Equals, 2)
}
开发者ID:anastasiamac,项目名称:utils,代码行数:9,代码来源:tags_test.go

示例8: TestAttachmentsUpdateShortCircuitDeath

func (s *attachmentsSuite) TestAttachmentsUpdateShortCircuitDeath(c *gc.C) {
	stateDir := c.MkDir()
	unitTag := names.NewUnitTag("mysql/0")
	abort := make(chan struct{})

	storageTag0 := names.NewStorageTag("data/0")
	storageTag1 := names.NewStorageTag("data/1")

	removed := set.NewTags()
	st := &mockStorageAccessor{
		unitStorageAttachments: func(u names.UnitTag) ([]params.StorageAttachmentId, error) {
			return nil, nil
		},
		remove: func(s names.StorageTag, u names.UnitTag) error {
			c.Assert(u, gc.Equals, unitTag)
			removed.Add(s)
			return nil
		},
	}

	att, err := storage.NewAttachments(st, unitTag, stateDir, abort)
	c.Assert(err, jc.ErrorIsNil)
	r := storage.NewResolver(att)

	// First make sure we create a storage-attached hook operation for
	// data/0. We do this to show that until the hook is *committed*,
	// we will still short-circuit removal.
	localState := resolver.LocalState{State: operation.State{
		Kind: operation.Continue,
	}}
	_, err = r.NextOp(localState, remotestate.Snapshot{
		Life: params.Alive,
		Storage: map[names.StorageTag]remotestate.StorageSnapshot{
			storageTag0: {
				Life:     params.Alive,
				Kind:     params.StorageKindBlock,
				Location: "/dev/sdb",
				Attached: true,
			},
		},
	}, &mockOperations{})
	c.Assert(err, jc.ErrorIsNil)

	for _, storageTag := range []names.StorageTag{storageTag0, storageTag1} {
		_, err = r.NextOp(localState, remotestate.Snapshot{
			Life: params.Alive,
			Storage: map[names.StorageTag]remotestate.StorageSnapshot{
				storageTag: {Life: params.Dying},
			},
		}, nil)
		c.Assert(err, gc.Equals, resolver.ErrNoOperation)
	}
	c.Assert(removed.SortedValues(), jc.DeepEquals, []names.Tag{
		storageTag0, storageTag1,
	})
}
开发者ID:bac,项目名称:juju,代码行数:56,代码来源:attachments_test.go

示例9: StorageTags

func (s *storageContextAccessor) StorageTags() []names.StorageTag {
	tags := set.NewTags()
	for tag := range s.storage {
		tags.Add(tag)
	}
	storageTags := make([]names.StorageTag, len(tags))
	for i, tag := range tags.SortedValues() {
		storageTags[i] = tag.(names.StorageTag)
	}
	return storageTags
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:11,代码来源:util_test.go

示例10: StorageTags

// StorageTags returns the names.StorageTags for the active storage attachments.
func (a *Attachments) StorageTags() []names.StorageTag {
	tags := set.NewTags()
	for tag := range a.storagers {
		tags.Add(tag)
	}
	storageTags := make([]names.StorageTag, tags.Size())
	for i, tag := range tags.SortedValues() {
		storageTags[i] = tag.(names.StorageTag)
	}
	return storageTags
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:12,代码来源:attachments.go

示例11: TestSize

func (tagSetSuite) TestSize(c *gc.C) {
	// Empty sets are empty.
	s := set.NewTags()
	c.Assert(s.Size(), gc.Equals, 0)

	s, err := set.NewTagsFromStrings(
		"unit-wordpress-0",
		"unit-rabbitmq-server-0",
	)
	c.Assert(err, gc.IsNil)
	c.Assert(s.Size(), gc.Equals, 2)
}
开发者ID:anastasiamac,项目名称:utils,代码行数:12,代码来源:tags_test.go

示例12: StorageTags

// StorageTags implements jujuc.ContextStorage.
func (c *ContextStorage) StorageTags() ([]names.StorageTag, error) {
	c.stub.AddCall("StorageTags")

	tags := set.NewTags()
	for tag := range c.info.Storage {
		tags.Add(tag)
	}
	storageTags := make([]names.StorageTag, tags.Size())
	for i, tag := range tags.SortedValues() {
		storageTags[i] = tag.(names.StorageTag)
	}
	return storageTags, c.stub.NextErr()
}
开发者ID:imoapps,项目名称:juju,代码行数:14,代码来源:storage.go

示例13: processPendingVolumeBlockDevices

// processPendingVolumeBlockDevices is called before waiting for any events,
// to force a block-device query for any volumes for which we have not
// previously observed block devices.
func processPendingVolumeBlockDevices(ctx *context) error {
	if len(ctx.pendingVolumeBlockDevices) == 0 {
		logger.Tracef("no pending volume block devices")
		return nil
	}
	volumeTags := make([]names.VolumeTag, len(ctx.pendingVolumeBlockDevices))
	for i, tag := range ctx.pendingVolumeBlockDevices.SortedValues() {
		volumeTags[i] = tag.(names.VolumeTag)
	}
	// Clear out the pending set, so we don't force-refresh again.
	ctx.pendingVolumeBlockDevices = set.NewTags()
	return refreshVolumeBlockDevices(ctx, volumeTags)
}
开发者ID:exekias,项目名称:juju,代码行数:16,代码来源:blockdevices.go

示例14: TestSizeDuplicate

func (tagSetSuite) TestSizeDuplicate(c *gc.C) {
	// Empty sets are empty.
	s := set.NewTags()
	c.Assert(s.Size(), gc.Equals, 0)

	// Size returns number of unique values.
	s, err := set.NewTagsFromStrings(
		"unit-wordpress-0",
		"unit-rabbitmq-server-0",
		"unit-wordpress-0",
	)
	c.Assert(err, gc.IsNil)
	c.Assert(s.Size(), gc.Equals, 2)
}
开发者ID:anastasiamac,项目名称:utils,代码行数:14,代码来源:tags_test.go

示例15: storageChanged

// storageChanged responds to unit storage changes.
func (f *filter) storageChanged(changed []names.StorageTag) {
	tags := set.NewTags() // f.storage is []StorageTag, not []Tag
	for _, tag := range f.storage {
		tags.Add(tag)
	}
	for _, tag := range changed {
		tags.Add(tag)
	}
	if len(f.storage) != len(tags) {
		storage := make([]names.StorageTag, len(tags))
		for i, tag := range tags.SortedValues() {
			storage[i] = tag.(names.StorageTag)
		}
		f.storage = storage
		f.outStorage = f.outStorageOn
	}
}
开发者ID:Pankov404,项目名称:juju,代码行数:18,代码来源:filter.go


注:本文中的github.com/juju/utils/set.NewTags函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。