Move ipset deletion condition check from DeleteSet to DeleteFromSet. (#602)
This commit is contained in:
Родитель
ea5c9a7c21
Коммит
d96246eae0
|
@ -291,7 +291,9 @@ func (ipsMgr *IpsetManager) DeleteFromSet(setName, ip string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
ipsMgr.DeleteSet(setName)
|
||||
if len(ipsMgr.setMap[setName].elements) == 0 {
|
||||
ipsMgr.DeleteSet(setName)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -195,9 +195,18 @@ func TestDeleteFromSet(t *testing.T) {
|
|||
t.Errorf("TestDeleteFromSet failed @ ipsMgr.AddToSet")
|
||||
}
|
||||
|
||||
if len(ipsMgr.setMap["test-set"].elements) != 1 {
|
||||
t.Errorf("TestDeleteFromSet failed @ ipsMgr.AddToSet")
|
||||
}
|
||||
|
||||
if err := ipsMgr.DeleteFromSet("test-set", "1.2.3.4"); err != nil {
|
||||
t.Errorf("TestDeleteFromSet failed @ ipsMgr.DeleteFromSet")
|
||||
}
|
||||
|
||||
// After deleting the only entry, "1.2.3.4" from "test-set", "test-set" ipset won't exist
|
||||
if _, exists := ipsMgr.setMap["test-set"]; exists {
|
||||
t.Errorf("TestDeleteFromSet failed @ ipsMgr.DeleteFromSet")
|
||||
}
|
||||
}
|
||||
|
||||
func TestClean(t *testing.T) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче