本文整理匯總了Golang中github.com/hashicorp/consul-template/dependency.ParseCatalogServices函數的典型用法代碼示例。如果您正苦於以下問題:Golang ParseCatalogServices函數的具體用法?Golang ParseCatalogServices怎麽用?Golang ParseCatalogServices使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ParseCatalogServices函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestServicesFunc_missingData
func TestServicesFunc_missingData(t *testing.T) {
d, err := dep.ParseCatalogServices("@non-existing")
if err != nil {
t.Fatal(err)
}
brain := NewBrain()
used := make(map[string]dep.Dependency)
missing := make(map[string]dep.Dependency)
f := servicesFunc(brain, used, missing)
result, err := f("@non-existing")
if err != nil {
t.Fatal(err)
}
expected := []*dep.CatalogService{}
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: servicesFunc
// servicesFunc returns or accumulates catalog services dependencies.
func servicesFunc(brain *Brain,
used, missing map[string]dep.Dependency) func(...string) ([]*dep.CatalogService, error) {
return func(s ...string) ([]*dep.CatalogService, error) {
result := make([]*dep.CatalogService, 0)
d, err := dep.ParseCatalogServices(s...)
if err != nil {
return nil, err
}
addDependency(used, d)
if value, ok := brain.Recall(d); ok {
return value.([]*dep.CatalogService), nil
}
addDependency(missing, d)
return result, nil
}
}
示例3: TestServicesFunc_hasData
func TestServicesFunc_hasData(t *testing.T) {
d, err := dep.ParseCatalogServices("@existing")
if err != nil {
t.Fatal(err)
}
data := []*dep.CatalogService{
&dep.CatalogService{Name: "a"},
&dep.CatalogService{Name: "b"},
}
brain := NewBrain()
brain.Remember(d, data)
used := make(map[string]dep.Dependency)
missing := make(map[string]dep.Dependency)
f := servicesFunc(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
//.........這裏部分代碼省略.........
})
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 {
t.Fatal(err)
}
brain.Remember(d, []*dep.HealthService{
&dep.HealthService{Node: "node1", Address: "1.2.3.4"},
&dep.HealthService{Node: "node2", Address: "5.6.7.8"},
})
d, err = dep.ParseCatalogServices("")
if err != nil {
t.Fatal(err)
}
brain.Remember(d, []*dep.CatalogService{
&dep.CatalogService{
Name: "service1",
Tags: []string{"production"},
},
&dep.CatalogService{
Name: "service2",
Tags: []string{"release", "production"},
},
})
d, err = dep.ParseVaultSecret("secret/foo/bar")
if err != nil {
t.Fatal(err)
}
brain.Remember(d, &dep.Secret{
LeaseID: "abcd1234",
LeaseDuration: 120,
Renewable: true,
Data: map[string]interface{}{"zip": "zap"},
})
if err := os.Setenv("foo", "bar"); err != nil {
t.Fatal(err)
}
d, err = dep.ParseFile("/path/to/json/file")
if err != nil {
t.Fatal(err)