agent: Changing to use nested JSON for watches

This commit is contained in:
Armon Dadgar 2014-08-21 11:52:36 -07:00
parent ad40ddf361
commit e877753162
2 changed files with 17 additions and 4 deletions

View File

@ -232,7 +232,7 @@ type Config struct {
// Watches are used to monitor various endpoints and to invoke a
// handler to act appropriately. These are managed entirely in the
// agent layer using the standard APIs.
Watches []string `mapstructure:"watches"`
Watches []map[string]interface{} `mapstructure:"watches"`
// AEInterval controls the anti-entropy interval. This is how often
// the agent attempts to reconcile it's local state with the server'

View File

@ -386,7 +386,7 @@ func TestDecodeConfig(t *testing.T) {
}
// Watches
input = `{"watches": ["type:keyprefix prefix:foo/ handler:foobar"]}`
input = `{"watches": [{"type":"keyprefix", "prefix":"foo/", "handler":"foobar"}]}`
config, err = DecodeConfig(bytes.NewReader([]byte(input)))
if err != nil {
t.Fatalf("err: %s", err)
@ -395,7 +395,14 @@ func TestDecodeConfig(t *testing.T) {
if len(config.Watches) != 1 {
t.Fatalf("bad: %#v", config)
}
if config.Watches[0] != "type:keyprefix prefix:foo/ handler:foobar" {
out := config.Watches[0]
exp := map[string]interface{}{
"type": "keyprefix",
"prefix": "foo/",
"handler": "foobar",
}
if !reflect.DeepEqual(out, exp) {
t.Fatalf("bad: %#v", config)
}
}
@ -552,7 +559,13 @@ func TestMergeConfig(t *testing.T) {
ACLTTLRaw: "15s",
ACLDownPolicy: "deny",
ACLDefaultPolicy: "deny",
Watches: []string{"type:keyprefix prefix:foobar/ handler:foo"},
Watches: []map[string]interface{}{
map[string]interface{}{
"type": "keyprefix",
"prefix": "foo/",
"handler": "foobar",
},
},
}
c := MergeConfig(a, b)