summaryrefslogtreecommitdiffstats
path: root/store/sql_audit_store_test.go
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2017-09-15 17:35:55 +0100
committerChristopher Speller <crspeller@gmail.com>2017-09-15 09:35:55 -0700
commit8195c80aa12136838ff4491fac989e0b946382b1 (patch)
treeda24729af5acbd3349c75923d346cfa7aa9ad95c /store/sql_audit_store_test.go
parent2628022275ef64fde95545abe4634b4bd7177844 (diff)
downloadchat-8195c80aa12136838ff4491fac989e0b946382b1.tar.gz
chat-8195c80aa12136838ff4491fac989e0b946382b1.tar.bz2
chat-8195c80aa12136838ff4491fac989e0b946382b1.zip
PLT-7639: Batch delete methods for data retention. (#7444)
Diffstat (limited to 'store/sql_audit_store_test.go')
-rw-r--r--store/sql_audit_store_test.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/store/sql_audit_store_test.go b/store/sql_audit_store_test.go
index 2e83bf563..8db5b5506 100644
--- a/store/sql_audit_store_test.go
+++ b/store/sql_audit_store_test.go
@@ -58,3 +58,32 @@ func TestSqlAuditStore(t *testing.T) {
t.Fatal(r2.Err)
}
}
+
+func TestAuditStorePermanentDeleteBatch(t *testing.T) {
+ Setup()
+
+ a1 := &model.Audit{UserId: model.NewId(), IpAddress: "ipaddress", Action: "Action"}
+ Must(store.Audit().Save(a1))
+ time.Sleep(10 * time.Millisecond)
+ a2 := &model.Audit{UserId: a1.UserId, IpAddress: "ipaddress", Action: "Action"}
+ Must(store.Audit().Save(a2))
+ time.Sleep(10 * time.Millisecond)
+ cutoff := model.GetMillis()
+ time.Sleep(10 * time.Millisecond)
+ a3 := &model.Audit{UserId: a1.UserId, IpAddress: "ipaddress", Action: "Action"}
+ Must(store.Audit().Save(a3))
+
+ if r := <-store.Audit().Get(a1.UserId, 0, 100); len(r.Data.(model.Audits)) != 3 {
+ t.Fatal("Expected 3 audits. Got ", len(r.Data.(model.Audits)))
+ }
+
+ Must(store.Audit().PermanentDeleteBatch(cutoff, 1000000))
+
+ if r := <-store.Audit().Get(a1.UserId, 0, 100); len(r.Data.(model.Audits)) != 1 {
+ t.Fatal("Expected 1 audit. Got ", len(r.Data.(model.Audits)))
+ }
+
+ if r2 := <-store.Audit().PermanentDeleteByUser(a1.UserId); r2.Err != nil {
+ t.Fatal(r2.Err)
+ }
+}