Browse Source

Add RunWithConfig and put Run signature back to normal

pull/4184/head
Matt Keeler 7 years ago
parent
commit
1fbe828c35
  1. 2
      agent/agent.go
  2. 2
      command/watch/watch.go
  3. 18
      watch/funcs_test.go
  4. 6
      watch/plan.go
  5. 2
      watch/plan_test.go

2
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)

2
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
}

18
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)
}
}()

6
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 {

2
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 {

Loading…
Cancel
Save