本文整理汇总了Golang中github.com/weaveworks/flux/common/store.Store.AddInstance方法的典型用法代码示例。如果您正苦于以下问题:Golang Store.AddInstance方法的具体用法?Golang Store.AddInstance怎么用?Golang Store.AddInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/weaveworks/flux/common/store.Store
的用法示例。
在下文中一共展示了Store.AddInstance方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: testInstances
func testInstances(s store.Store, t *testing.T) {
require.Nil(t, s.AddService("svc", testService))
require.Nil(t, s.AddInstance("svc", "inst", testInst))
instances := func() map[string]data.Instance {
insts := make(map[string]data.Instance)
require.Nil(t, store.ForeachInstance(s, "svc", func(_, n string, inst data.Instance) error {
insts[n] = inst
return nil
}))
return insts
}
require.Equal(t, map[string]data.Instance{"inst": testInst}, instances())
serviceInstances := func() map[string]data.Instance {
insts := make(map[string]data.Instance)
require.Nil(t, store.ForeachServiceInstance(s, nil, func(sn string, in string, inst data.Instance) error {
insts[sn+" "+in] = inst
return nil
}))
return insts
}
require.Equal(t, map[string]data.Instance{"svc inst": testInst}, serviceInstances())
require.Nil(t, s.RemoveInstance("svc", "inst"))
require.Equal(t, map[string]data.Instance{}, instances())
require.Equal(t, map[string]data.Instance{}, serviceInstances())
}
示例2: 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})
}