Add RunWithConfig and put Run signature back to normal

This commit is contained in:
Matt Keeler 2018-05-31 20:22:14 -04:00
parent f300d7bc65
commit 4858aa6be4
5 changed files with 17 additions and 13 deletions

View File

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

View File

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

View File

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

View File

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

View File

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