本文整理汇总了Golang中github.com/hashicorp/consul-template/dependency.ParseStoreKey函数的典型用法代码示例。如果您正苦于以下问题:Golang ParseStoreKey函数的具体用法?Golang ParseStoreKey怎么用?Golang ParseStoreKey使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ParseStoreKey函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestKeyFunc_hasData
func TestKeyFunc_hasData(t *testing.T) {
d, err := dep.ParseStoreKey("existing")
if err != nil {
t.Fatal(err)
}
brain := NewBrain()
brain.Remember(d, "contents")
used := make(map[string]dep.Dependency)
missing := make(map[string]dep.Dependency)
f := keyFunc(brain, used, missing)
result, err := f("existing")
if err != nil {
t.Fatal(err)
}
if result != "contents" {
t.Errorf("expected %q to be %q", result, "contents")
}
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")
}
}
开发者ID:necroscope,项目名称:consul-template,代码行数:30,代码来源:template_functions_test.go
示例2: TestKeyFunc_missingData
func TestKeyFunc_missingData(t *testing.T) {
d, err := dep.ParseStoreKey("non-existing")
if err != nil {
t.Fatal(err)
}
brain := NewBrain()
used := make(map[string]dep.Dependency)
missing := make(map[string]dep.Dependency)
f := keyFunc(brain, used, missing)
result, err := f("non-existing")
if err != nil {
t.Fatal(err)
}
if result != "" {
t.Errorf("expected %q to be %q", result, "")
}
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")
}
}
开发者ID:necroscope,项目名称:consul-template,代码行数:29,代码来源:template_functions_test.go
示例3: keyFunc
// keyFunc returns or accumulates key dependencies.
func keyFunc(brain *Brain,
used, missing map[string]dep.Dependency) func(string) (string, error) {
return func(s string) (string, error) {
if len(s) == 0 {
return "", nil
}
d, err := dep.ParseStoreKey(s)
if err != nil {
return "", err
}
addDependency(used, d)
if value, ok := brain.Recall(d); ok {
if value == nil {
return "", nil
} else {
return value.(string), nil
}
}
addDependency(missing, d)
return "", nil
}
}
开发者ID:hashbrowncipher,项目名称:consul-template,代码行数:28,代码来源:template_functions.go
示例4: TestRunner_onceAlreadyRenderedDoesNotHangOrRunCommands
func TestRunner_onceAlreadyRenderedDoesNotHangOrRunCommands(t *testing.T) {
outFile := test.CreateTempfile(nil, t)
os.Remove(outFile.Name())
defer os.Remove(outFile.Name())
out := test.CreateTempfile([]byte("redis"), t)
defer os.Remove(out.Name())
in := test.CreateTempfile([]byte(`{{ key "service_name"}}`), t)
defer test.DeleteTempfile(in, t)
outTemplateA := test.CreateTempfile(nil, t)
defer test.DeleteTempfile(outTemplateA, t)
config := DefaultConfig()
config.Merge(&Config{
ConfigTemplates: []*ConfigTemplate{
&ConfigTemplate{
Source: in.Name(),
Destination: out.Name(),
Command: fmt.Sprintf("echo 'foo' >> %s", outFile.Name()),
Wait: &watch.Wait{},
},
},
})
runner, err := NewRunner(config, false, true)
if err != nil {
t.Fatal(err)
}
d, err := dep.ParseStoreKey("service_name")
if err != nil {
t.Fatal(err)
}
data := "redis"
runner.dependencies[d.HashCode()] = d
runner.watcher.ForceWatching(d, true)
runner.Receive(d, data)
go runner.Start()
select {
case err := <-runner.ErrCh:
t.Fatal(err)
case <-runner.DoneCh:
case <-time.After(5 * time.Millisecond):
t.Fatal("runner should have stopped")
runner.Stop()
}
_, err = os.Stat(outFile.Name())
if err == nil {
t.Fatal("expected command to not be run")
}
if !os.IsNotExist(err) {
t.Fatal(err)
}
}
开发者ID:yuanfeng0905,项目名称:consul-template,代码行数:59,代码来源:runner_test.go
示例5: TestExecute_missingDependencies
func TestExecute_missingDependencies(t *testing.T) {
contents := []byte(`{{key "foo"}}`)
in := test.CreateTempfile(contents, t)
defer test.DeleteTempfile(in, t)
tmpl, err := NewTemplate(in.Name())
if err != nil {
t.Fatal(err)
}
brain := NewBrain()
used, missing, result, err := tmpl.Execute(brain)
if err != nil {
t.Fatal(err)
}
if num := len(used); num != 1 {
t.Fatalf("expected 1 used, got: %d", num)
}
if num := len(missing); num != 1 {
t.Fatalf("expected 1 missing, got: %d", num)
}
expected, err := dep.ParseStoreKey("foo")
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(missing[0], expected) {
t.Errorf("expected %q to be %q", missing[0], expected)
}
if num := len(used); num != 1 {
t.Fatalf("expected 1 used, got %d", num)
}
if !reflect.DeepEqual(used[0], expected) {
t.Errorf("expected %q to be %q", used[0], expected)
}
expectedResult := []byte("")
if !bytes.Equal(result, expectedResult) {
t.Errorf("expected %q to be %q", result, expectedResult)
}
}
开发者ID:necroscope,项目名称:consul-template,代码行数:46,代码来源:template_test.go
示例6: TestReceive_addsToBrain
func TestReceive_addsToBrain(t *testing.T) {
runner, err := NewRunner(DefaultConfig(), false, false)
if err != nil {
t.Fatal(err)
}
d, err := dep.ParseStoreKey("foo")
if err != nil {
t.Fatal(err)
}
data := "some value"
runner.dependencies[d.HashCode()] = d
runner.Receive(d, data)
value, ok := runner.brain.Recall(d)
if !ok {
t.Fatalf("expected brain to have data")
}
if data != value {
t.Errorf("expected %q to be %q", data, value)
}
}
开发者ID:robinsq,项目名称:consul-template,代码行数:22,代码来源:runner_test.go
示例7: keyExistsFunc
// keyExistsFunc returns true if a key exists, false otherwise.
func keyExistsFunc(brain *Brain,
used, missing map[string]dep.Dependency) func(string) (bool, error) {
return func(s string) (bool, error) {
if len(s) == 0 {
return false, nil
}
d, err := dep.ParseStoreKey(s)
if err != nil {
return false, err
}
d.SetExistenceCheck(true)
addDependency(used, d)
if value, ok := brain.Recall(d); ok {
return value.(bool), nil
}
addDependency(missing, d)
return false, nil
}
}
开发者ID:nak3,项目名称:nomad,代码行数:25,代码来源:template_functions.go
示例8: TestExecute_renders
//.........这里部分代码省略.........
toYAML:
{{ tree "config/redis" | explode | toYAML }}
Math Functions
--------------
add:{{ 2 | add 2 }}
subtract:{{ 2 | subtract 2 }}
multiply:{{ 2 | multiply 2 }}
divide:{{ 2 | divide 2 }}
`), t)
defer test.DeleteTempfile(in, t)
tmpl, err := NewTemplate(in.Name())
if err != nil {
t.Fatal(err)
}
brain := NewBrain()
var d dep.Dependency
d, err = dep.ParseDatacenters()
if err != nil {
t.Fatal(err)
}
brain.Remember(d, []string{"dc1", "dc2"})
d, err = dep.ParseFile("/path/to/file")
if err != nil {
t.Fatal(err)
}
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)
开发者ID:necroscope,项目名称:consul-template,代码行数:67,代码来源:template_test.go
注:本文中的github.com/hashicorp/consul-template/dependency.ParseStoreKey函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论