From a82726f0b8e82c8ebb1208f4a7c2ee9787e9d415 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 13 Jun 2018 08:21:50 +0200 Subject: [PATCH] agent: RemoveProxy also removes the proxy service --- agent/agent.go | 9 ++++++++- agent/agent_test.go | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/agent/agent.go b/agent/agent.go index 7751a2f1c7..1870e477c3 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -2185,7 +2185,14 @@ func (a *Agent) RemoveProxy(proxyID string, persist bool) error { } // Remove the proxy from the local state - if _, err := a.State.RemoveProxy(proxyID); err != nil { + p, err := a.State.RemoveProxy(proxyID) + if err != nil { + return err + } + + // Remove the proxy service as well. The proxy ID is also the ID + // of the servie, but we might as well use the service pointer. + if err := a.RemoveService(p.Proxy.ProxyService.ID, persist); err != nil { return err } diff --git a/agent/agent_test.go b/agent/agent_test.go index cb7c4d6fcf..9a7c2a8dee 100644 --- a/agent/agent_test.go +++ b/agent/agent_test.go @@ -2706,14 +2706,14 @@ func TestAgent_RemoveProxy(t *testing.T) { // Test the ID was created as we expect. gotProxy := a.State.Proxy("web-proxy") - gotProxy.Proxy.ProxyService = nil - require.Equal(pReg, gotProxy.Proxy) + require.NotNil(gotProxy) err := a.RemoveProxy("web-proxy", false) require.NoError(err) gotProxy = a.State.Proxy("web-proxy") require.Nil(gotProxy) + require.Nil(a.State.Service("web-proxy"), "web-proxy service") // Removing invalid proxy should be an error err = a.RemoveProxy("foobar", false)