本文整理汇总了Golang中github.com/hashicorp/consul-template/dependency.ParseCatalogNodes函数的典型用法代码示例。如果您正苦于以下问题:Golang ParseCatalogNodes函数的具体用法?Golang ParseCatalogNodes怎么用?Golang ParseCatalogNodes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ParseCatalogNodes函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestNodesFunc_missingData
func TestNodesFunc_missingData(t *testing.T) {
d, err := dep.ParseCatalogNodes("@non-existing")
if err != nil {
t.Fatal(err)
}
brain := NewBrain()
used := make(map[string]dep.Dependency)
missing := make(map[string]dep.Dependency)
f := nodesFunc(brain, used, missing)
result, err := f("@non-existing")
if err != nil {
t.Fatal(err)
}
expected := []*dep.Node{}
if !reflect.DeepEqual(result, expected) {
t.Errorf("expected %q to be %q", result, expected)
}
if _, ok := used[d.HashCode()]; !ok {
t.Errorf("expected dep to be used")
}
if _, ok := missing[d.HashCode()]; !ok {
t.Errorf("expected dep to be missing")
}
}
示例2: nodesFunc
// nodesFunc returns or accumulates catalog node dependencies.
func nodesFunc(brain *Brain,
used, missing map[string]dep.Dependency) func(...string) ([]*dep.Node, error) {
return func(s ...string) ([]*dep.Node, error) {
result := make([]*dep.Node, 0)
d, err := dep.ParseCatalogNodes(s...)
if err != nil {
return nil, err
}
addDependency(used, d)
if value, ok := brain.Recall(d); ok {
return value.([]*dep.Node), nil
}
addDependency(missing, d)
return result, nil
}
}
示例3: TestNodesFunc_hasData
func TestNodesFunc_hasData(t *testing.T) {
d, err := dep.ParseCatalogNodes("@existing")
if err != nil {
t.Fatal(err)
}
data := []*dep.Node{
&dep.Node{Node: "a"},
&dep.Node{Node: "b"},
}
brain := NewBrain()
brain.Remember(d, data)
used := make(map[string]dep.Dependency)
missing := make(map[string]dep.Dependency)
f := nodesFunc(brain, used, missing)
result, err := f("@existing")
if err != nil {
t.Fatal(err)
}
expected := data
if !reflect.DeepEqual(result, expected) {
t.Errorf("expected %q to be %q", result, expected)
}
if len(missing) != 0 {
t.Errorf("expected missing to have 0 elements, but had %d", len(missing))
}
if _, ok := used[d.HashCode()]; !ok {
t.Errorf("expected dep to be used")
}
}
示例4: TestExecute_renders
//.........这里部分代码省略.........
}
brain.Remember(d, "some content")
d, err = dep.ParseStoreKey("config/redis/maxconns")
if err != nil {
t.Fatal(err)
}
brain.Remember(d, "5")
d, err = dep.ParseStoreKeyPrefix("config/redis")
if err != nil {
t.Fatal(err)
}
brain.Remember(d, []*dep.KeyPair{
&dep.KeyPair{Key: "", Value: ""},
&dep.KeyPair{Key: "admin/port", Value: "1134"},
&dep.KeyPair{Key: "maxconns", Value: "5"},
&dep.KeyPair{Key: "minconns", Value: "2"},
})
d, err = dep.ParseCatalogNode()
if err != nil {
t.Fatal(err)
}
brain.Remember(d, &dep.NodeDetail{
Node: &dep.Node{Node: "node1"},
Services: dep.NodeServiceList([]*dep.NodeService{
&dep.NodeService{
Service: "service1",
},
}),
})
d, err = dep.ParseCatalogNodes("")
if err != nil {
t.Fatal(err)
}
brain.Remember(d, []*dep.Node{
&dep.Node{Node: "node1"},
&dep.Node{Node: "node2"},
})
d, err = dep.ParseHealthServices("webapp")
if err != nil {
t.Fatal(err)
}
brain.Remember(d, []*dep.HealthService{
&dep.HealthService{
Node: "node1",
Address: "1.2.3.4",
Tags: []string{"release"},
},
&dep.HealthService{
Node: "node2",
Address: "5.6.7.8",
Tags: []string{"release", "production"},
},
&dep.HealthService{
Node: "node3",
Address: "9.10.11.12",
Tags: []string{"production"},
},
})
d, err = dep.ParseHealthServices("webapp", "any")
if err != nil {