From 4858aa6be46546c81006b0179c7314d86cd3a971 Mon Sep 17 00:00:00 2001 From: Matt Keeler Date: Thu, 31 May 2018 20:22:14 -0400 Subject: [PATCH] Add RunWithConfig and put Run signature back to normal --- agent/agent.go | 2 +- command/watch/watch.go | 2 +- watch/funcs_test.go | 18 +++++++++--------- watch/plan.go | 6 +++++- watch/plan_test.go | 2 +- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/agent/agent.go b/agent/agent.go index d6b3eabe7..f11b71782 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -686,7 +686,7 @@ func (a *Agent) reloadWatches(cfg *config.RuntimeConfig) error { config.TLSConfig.Address = addr } - if err := wp.Run(addr, config); err != nil { + if err := wp.RunWithConfig(addr, config); err != nil { a.logger.Printf("[ERR] agent: Failed to run watch: %v", err) } }(wp) diff --git a/command/watch/watch.go b/command/watch/watch.go index 14e4701b8..3b8c67836 100644 --- a/command/watch/watch.go +++ b/command/watch/watch.go @@ -226,7 +226,7 @@ func (c *cmd) Run(args []string) int { }() // Run the watch - if err := wp.Run(c.http.Addr(), nil); err != nil { + if err := wp.Run(c.http.Addr()); err != nil { c.UI.Error(fmt.Sprintf("Error querying Consul agent: %s", err)) return 1 } diff --git a/watch/funcs_test.go b/watch/funcs_test.go index 35de2387a..190ae24fa 100644 --- a/watch/funcs_test.go +++ b/watch/funcs_test.go @@ -64,7 +64,7 @@ func TestKeyWatch(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - if err := plan.Run(a.HTTPAddr(), nil); err != nil { + if err := plan.Run(a.HTTPAddr()); err != nil { t.Fatalf("err: %v", err) } }() @@ -118,7 +118,7 @@ func TestKeyWatch_With_PrefixDelete(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - if err := plan.Run(a.HTTPAddr(), nil); err != nil { + if err := plan.Run(a.HTTPAddr()); err != nil { t.Fatalf("err: %v", err) } }() @@ -171,7 +171,7 @@ func TestKeyPrefixWatch(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - if err := plan.Run(a.HTTPAddr(), nil); err != nil { + if err := plan.Run(a.HTTPAddr()); err != nil { t.Fatalf("err: %v", err) } }() @@ -225,7 +225,7 @@ func TestServicesWatch(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - if err := plan.Run(a.HTTPAddr(), nil); err != nil { + if err := plan.Run(a.HTTPAddr()); err != nil { t.Fatalf("err: %v", err) } }() @@ -276,7 +276,7 @@ func TestNodesWatch(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - if err := plan.Run(a.HTTPAddr(), nil); err != nil { + if err := plan.Run(a.HTTPAddr()); err != nil { t.Fatalf("err: %v", err) } }() @@ -332,7 +332,7 @@ func TestServiceWatch(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - if err := plan.Run(a.HTTPAddr(), nil); err != nil { + if err := plan.Run(a.HTTPAddr()); err != nil { t.Fatalf("err: %v", err) } }() @@ -393,7 +393,7 @@ func TestChecksWatch_State(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - if err := plan.Run(a.HTTPAddr(), nil); err != nil { + if err := plan.Run(a.HTTPAddr()); err != nil { t.Fatalf("err: %v", err) } }() @@ -459,7 +459,7 @@ func TestChecksWatch_Service(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - if err := plan.Run(a.HTTPAddr(), nil); err != nil { + if err := plan.Run(a.HTTPAddr()); err != nil { t.Fatalf("err: %v", err) } }() @@ -510,7 +510,7 @@ func TestEventWatch(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - if err := plan.Run(a.HTTPAddr(), nil); err != nil { + if err := plan.Run(a.HTTPAddr()); err != nil { t.Fatalf("err: %v", err) } }() diff --git a/watch/plan.go b/watch/plan.go index 2743518da..fff9da7c7 100644 --- a/watch/plan.go +++ b/watch/plan.go @@ -19,8 +19,12 @@ const ( maxBackoffTime = 180 * time.Second ) +func (p *Plan) Run(address string) error { + return p.RunWithConfig(address, nil) +} + // Run is used to run a watch plan -func (p *Plan) Run(address string, conf *consulapi.Config) error { +func (p *Plan) RunWithConfig(address string, conf *consulapi.Config) error { // Setup the client p.address = address if conf == nil { diff --git a/watch/plan_test.go b/watch/plan_test.go index c7b16fade..16e4cfbc2 100644 --- a/watch/plan_test.go +++ b/watch/plan_test.go @@ -47,7 +47,7 @@ func TestRun_Stop(t *testing.T) { errCh := make(chan error, 1) go func() { - errCh <- plan.Run("127.0.0.1:8500", nil) + errCh <- plan.Run("127.0.0.1:8500") }() select {