fix ban flush (#277)

* fix ban flush by soft-deleting entries in database
* fix unit tests accordingly
This commit is contained in:
registergoofy 2020-10-01 08:26:59 +02:00 committed by GitHub
parent a8e6f9d1e5
commit 9b97633043
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 5 deletions

View file

@ -25,6 +25,15 @@ func (c *Context) DeleteBan(target string) (int, 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{}
records := c.Db.Unscoped().Delete(&allBa)
if records.Error != nil {

View file

@ -20,7 +20,7 @@ func TestNoCleanUpParams(t *testing.T) {
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")
}
@ -78,7 +78,7 @@ func TestNoCleanUp(t *testing.T) {
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")
}
@ -143,7 +143,7 @@ func TestCleanUpByCount(t *testing.T) {
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")
}
@ -255,7 +255,7 @@ func TestCleanUpByAge(t *testing.T) {
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")
}

View file

@ -27,7 +27,7 @@ func TestFetchBans(t *testing.T) {
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")
}