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 e2653bec02
commit a82726f0b8
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 // 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 return err
} }

View File

@ -2706,14 +2706,14 @@ func TestAgent_RemoveProxy(t *testing.T) {
// Test the ID was created as we expect. // Test the ID was created as we expect.
gotProxy := a.State.Proxy("web-proxy") gotProxy := a.State.Proxy("web-proxy")
gotProxy.Proxy.ProxyService = nil require.NotNil(gotProxy)
require.Equal(pReg, gotProxy.Proxy)
err := a.RemoveProxy("web-proxy", false) err := a.RemoveProxy("web-proxy", false)
require.NoError(err) require.NoError(err)
gotProxy = a.State.Proxy("web-proxy") gotProxy = a.State.Proxy("web-proxy")
require.Nil(gotProxy) require.Nil(gotProxy)
require.Nil(a.State.Service("web-proxy"), "web-proxy service")
// Removing invalid proxy should be an error // Removing invalid proxy should be an error
err = a.RemoveProxy("foobar", false) err = a.RemoveProxy("foobar", false)