agent: RemoveProxy also removes the proxy service

This commit is contained in:
Mitchell Hashimoto 2018-06-13 08:21:50 +02:00 committed by Jack Pearkes
parent 8c349a2b24
commit 0d457a3e71
2 changed files with 10 additions and 3 deletions

View File

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

View File

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