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


Golang Store.SetContainerRule方法代码示例

本文整理汇总了Golang中github.com/weaveworks/flux/common/store.Store.SetContainerRule方法的典型用法代码示例。如果您正苦于以下问题:Golang Store.SetContainerRule方法的具体用法?Golang Store.SetContainerRule怎么用?Golang Store.SetContainerRule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/weaveworks/flux/common/store.Store的用法示例。


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

示例1: testWatchServices

func testWatchServices(s store.Store, t *testing.T) {
	check := func(opts store.QueryServiceOptions, body func(w *watcher), changes ...data.ServiceChange) {
		w := newWatcher(s, opts)
		body(w)
		// Yuck.  There's a race between making a change in
		// etcd, and hearing about it via the watch, and I
		// haven't found a nicer way to avoid it.
		time.Sleep(100 * time.Millisecond)
		w.stop()
		require.Equal(t, changes, w.changes)
		require.Nil(t, s.RemoveAllServices())
	}

	check(store.QueryServiceOptions{}, func(w *watcher) {
		require.Nil(t, s.AddService("svc", testService))
	}, data.ServiceChange{"svc", false})

	require.Nil(t, s.AddService("svc", testService))
	check(store.QueryServiceOptions{}, func(w *watcher) {
		require.Nil(t, s.RemoveAllServices())
		require.Nil(t, s.AddService("svc", testService))
		require.Nil(t, s.RemoveService("svc"))
	}, data.ServiceChange{"svc", true}, data.ServiceChange{"svc", false},
		data.ServiceChange{"svc", true})

	// WithInstances false, so adding an instance should not
	// cause an event
	require.Nil(t, s.AddService("svc", testService))
	check(store.QueryServiceOptions{}, func(w *watcher) {
		require.Nil(t, s.AddInstance("svc", "inst", testInst))
	})

	// WithInstances true, so instance changes should
	// cause events
	require.Nil(t, s.AddService("svc", testService))
	check(store.QueryServiceOptions{WithInstances: true},
		func(w *watcher) {
			require.Nil(t, s.AddInstance("svc", "inst", testInst))
			require.Nil(t, s.RemoveInstance("svc", "inst"))
		}, data.ServiceChange{"svc", false},
		data.ServiceChange{"svc", false})

	// WithContainerRules false, so adding a rule should not
	// cause an event
	require.Nil(t, s.AddService("svc", testService))
	check(store.QueryServiceOptions{}, func(w *watcher) {
		require.Nil(t, s.SetContainerRule("svc", "group", testRule))
	})

	// WithContainerRules true, so instance changes should
	// cause events
	require.Nil(t, s.AddService("svc", testService))
	check(store.QueryServiceOptions{WithContainerRules: true},
		func(w *watcher) {
			require.Nil(t, s.SetContainerRule("svc", "group", testRule))
			require.Nil(t, s.RemoveContainerRule("svc", "group"))
		}, data.ServiceChange{"svc", false},
		data.ServiceChange{"svc", false})
}
开发者ID:errordeveloper,项目名称:flux,代码行数:59,代码来源:suite.go

示例2: addGroup

func addGroup(st store.Store, serviceName string, addr *data.AddressSpec, labels ...string) {
	if len(labels)%2 != 0 {
		panic("Expected key value ... as arguments")
	}
	sel := make(map[string]string)
	for i := 0; i < len(labels); i += 2 {
		sel[labels[i]] = labels[i+1]
	}

	if addr == nil {
		addr = &data.AddressSpec{"fixed", 80}
	}

	st.SetContainerRule(serviceName, GROUP, data.ContainerRule{*addr, sel})
}
开发者ID:errordeveloper,项目名称:flux,代码行数:15,代码来源:listener_test.go

示例3: testRules

func testRules(s store.Store, t *testing.T) {
	require.Nil(t, s.AddService("svc", testService))
	require.Nil(t, s.SetContainerRule("svc", "group", testRule))

	svc, err := s.GetService("svc", store.QueryServiceOptions{WithContainerRules: true})
	require.Nil(t, err)

	require.Equal(t, []store.ContainerRuleInfo{
		store.ContainerRuleInfo{
			Name:          "group",
			ContainerRule: testRule,
		},
	}, svc.ContainerRules)

	require.Nil(t, s.RemoveContainerRule("svc", "group"))
	svc, err = s.GetService("svc", store.QueryServiceOptions{WithContainerRules: true})
	require.Nil(t, err)
	require.Empty(t, svc.ContainerRules)
}
开发者ID:errordeveloper,项目名称:flux,代码行数:19,代码来源:suite.go


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