fix ban flush (#277)
* fix ban flush by soft-deleting entries in database * fix unit tests accordingly
This commit is contained in:
parent
a8e6f9d1e5
commit
9b97633043
3 changed files with 14 additions and 5 deletions
|
@ -25,6 +25,15 @@ func (c *Context) DeleteBan(target string) (int, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) DeleteAll() error {
|
func (c *Context) DeleteAll() error {
|
||||||
|
allBa := types.BanApplication{}
|
||||||
|
records := c.Db.Delete(&allBa)
|
||||||
|
if records.Error != nil {
|
||||||
|
return records.Error
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Context) HardDeleteAll() error {
|
||||||
allBa := types.BanApplication{}
|
allBa := types.BanApplication{}
|
||||||
records := c.Db.Unscoped().Delete(&allBa)
|
records := c.Db.Unscoped().Delete(&allBa)
|
||||||
if records.Error != nil {
|
if records.Error != nil {
|
||||||
|
|
|
@ -20,7 +20,7 @@ func TestNoCleanUpParams(t *testing.T) {
|
||||||
t.Fatalf("failed to create simple sqlite")
|
t.Fatalf("failed to create simple sqlite")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ctx.DeleteAll(); err != nil {
|
if err := ctx.HardDeleteAll(); err != nil {
|
||||||
t.Fatalf("failed to flush existing bans")
|
t.Fatalf("failed to flush existing bans")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ func TestNoCleanUp(t *testing.T) {
|
||||||
t.Fatalf("failed to create simple sqlite")
|
t.Fatalf("failed to create simple sqlite")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ctx.DeleteAll(); err != nil {
|
if err := ctx.HardDeleteAll(); err != nil {
|
||||||
t.Fatalf("failed to flush existing bans")
|
t.Fatalf("failed to flush existing bans")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ func TestCleanUpByCount(t *testing.T) {
|
||||||
t.Fatalf("failed to create simple sqlite")
|
t.Fatalf("failed to create simple sqlite")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ctx.DeleteAll(); err != nil {
|
if err := ctx.HardDeleteAll(); err != nil {
|
||||||
t.Fatalf("failed to flush existing bans")
|
t.Fatalf("failed to flush existing bans")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,7 +255,7 @@ func TestCleanUpByAge(t *testing.T) {
|
||||||
t.Fatalf("failed to create simple sqlite")
|
t.Fatalf("failed to create simple sqlite")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ctx.DeleteAll(); err != nil {
|
if err := ctx.HardDeleteAll(); err != nil {
|
||||||
t.Fatalf("failed to flush existing bans")
|
t.Fatalf("failed to flush existing bans")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ func TestFetchBans(t *testing.T) {
|
||||||
t.Fatalf("failed to create simple sqlite")
|
t.Fatalf("failed to create simple sqlite")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ctx.DeleteAll(); err != nil {
|
if err := ctx.HardDeleteAll(); err != nil {
|
||||||
t.Fatalf("failed to flush existing bans")
|
t.Fatalf("failed to flush existing bans")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue