From e877753162096049b0c8ef3d37ef3a7379e4aad1 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Thu, 21 Aug 2014 11:52:36 -0700 Subject: [PATCH] agent: Changing to use nested JSON for watches --- command/agent/config.go | 2 +- command/agent/config_test.go | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/command/agent/config.go b/command/agent/config.go index e40f4b568b..cba6f3e8f2 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -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' diff --git a/command/agent/config_test.go b/command/agent/config_test.go index b57037a51e..75c0610a9e 100644 --- a/command/agent/config_test.go +++ b/command/agent/config_test.go @@ -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)