blob: 17d53e5e861a130c1ef8b4fe465b5e5f4bb42381 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package store
import (
"testing"
"time"
"github.com/mattermost/platform/model"
)
func TestSqlAuditStore(t *testing.T) {
Setup()
audit := &model.Audit{UserId: model.NewId(), IpAddress: "ipaddress", Action: "Action"}
Must(store.Audit().Save(audit))
time.Sleep(100 * time.Millisecond)
Must(store.Audit().Save(audit))
time.Sleep(100 * time.Millisecond)
Must(store.Audit().Save(audit))
time.Sleep(100 * time.Millisecond)
audit.ExtraInfo = "extra"
time.Sleep(100 * time.Millisecond)
Must(store.Audit().Save(audit))
time.Sleep(100 * time.Millisecond)
c := store.Audit().Get(audit.UserId, 0, 100)
result := <-c
audits := result.Data.(model.Audits)
if len(audits) != 4 {
t.Fatal("Failed to save and retrieve 4 audit logs")
}
if audits[0].ExtraInfo != "extra" {
t.Fatal("Failed to save property for extra info")
}
c = store.Audit().Get("missing", 0, 100)
result = <-c
audits = result.Data.(model.Audits)
if len(audits) != 0 {
t.Fatal("Should have returned empty because user_id is missing")
}
c = store.Audit().Get("", 0, 100)
result = <-c
audits = result.Data.(model.Audits)
if len(audits) < 4 {
t.Fatal("Failed to save and retrieve 4 audit logs")
}
if r2 := <-store.Audit().PermanentDeleteByUser(audit.UserId); r2.Err != nil {
t.Fatal(r2.Err)
}
}
|