-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
audit_store.go
50 lines (38 loc) · 1.38 KB
/
audit_store.go
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
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package storetest
import (
"testing"
"time"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/store"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestAuditStore(t *testing.T, ss store.Store) {
t.Run("", func(t *testing.T) { testAuditStore(t, ss) })
}
func testAuditStore(t *testing.T, ss store.Store) {
audit := &model.Audit{UserId: model.NewId(), IpAddress: "ipaddress", Action: "Action"}
require.Nil(t, ss.Audit().Save(audit))
time.Sleep(100 * time.Millisecond)
require.Nil(t, ss.Audit().Save(audit))
time.Sleep(100 * time.Millisecond)
require.Nil(t, ss.Audit().Save(audit))
time.Sleep(100 * time.Millisecond)
audit.ExtraInfo = "extra"
time.Sleep(100 * time.Millisecond)
require.Nil(t, ss.Audit().Save(audit))
time.Sleep(100 * time.Millisecond)
audits, err := ss.Audit().Get(audit.UserId, 0, 100)
require.Nil(t, err)
assert.Len(t, audits, 4)
assert.Equal(t, "extra", audits[0].ExtraInfo)
audits, err = ss.Audit().Get("missing", 0, 100)
require.Nil(t, err)
assert.Empty(t, audits)
audits, err = ss.Audit().Get("", 0, 100)
require.Nil(t, err)
require.Len(t, audits, 4, "Failed to save and retrieve 4 audit logs")
require.Nil(t, ss.Audit().PermanentDeleteByUser(audit.UserId))
}