From 0cd25cf598096505f9b77c4d0a64bd1bbf08d6fe Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Fri, 10 Jan 2020 15:28:58 +0300 Subject: [PATCH] Merge: - clients: fix rename Close #1340 Squashed commit of the following: commit 95f0291c681f98c29f4014b651c159d387301af4 Author: Simon Zolin Date: Thu Jan 9 18:56:23 2020 +0300 add test commit 293be277e245ff2f430e8c1e9ee3e82dc7da0995 Author: Simon Zolin Date: Thu Jan 9 16:04:36 2020 +0300 - clients: fix rename --- home/clients.go | 8 ++++++-- home/clients_test.go | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/home/clients.go b/home/clients.go index b5ca3d2d..3b94edef 100644 --- a/home/clients.go +++ b/home/clients.go @@ -468,12 +468,16 @@ func (clients *clientsContainer) Update(name string, c Client) error { // update Name index if old.Name != c.Name { + delete(clients.list, old.Name) clients.list[c.Name] = old } // update upstreams cache - delete(clients.upstreamsCache, name) - delete(clients.upstreamsCache, old.Name) + if old.Name != c.Name { + delete(clients.upstreamsCache, old.Name) + } else { + delete(clients.upstreamsCache, c.Name) + } *old = c return nil diff --git a/home/clients_test.go b/home/clients_test.go index 490035ed..e227d699 100644 --- a/home/clients_test.go +++ b/home/clients_test.go @@ -114,6 +114,7 @@ func TestClients(t *testing.T) { c = Client{} c, b = clients.Find("1.1.1.2") assert.True(t, b && c.Name == "client1-renamed" && c.IDs[0] == "1.1.1.2" && c.UseOwnSettings) + assert.True(t, clients.list["client1"] == nil) // failed remove - no such name if clients.Del("client3") {