-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathdatabase_test.go
More file actions
53 lines (42 loc) · 1.29 KB
/
database_test.go
File metadata and controls
53 lines (42 loc) · 1.29 KB
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
package server
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func testDatabase(t *testing.T, db Database) {
t.Run("ForumPosts", func(t *testing.T) {
testDatabase_ForumPosts(t, db)
})
}
func testDatabase_ForumPosts(t *testing.T, db Database) {
locale := Locales[0]
post1 := &ForumPost{
Id: 9000,
Poster: "Chris",
Time: time.Unix(1486332365, 0),
}
post2 := &ForumPost{
Id: 9001,
Poster: "Chris",
Time: time.Unix(1486332364, 0),
}
db.AddActivity([]Activity{post1, post2})
all := func(a Activity) bool { return true }
posts, next, err := db.Activity(locale, "", 1, all)
require.NoError(t, err)
require.Equal(t, 1, len(posts))
assert.Equal(t, post1.Id, posts[0].(*ForumPost).Id)
assert.Equal(t, post1.Poster, posts[0].(*ForumPost).Poster)
assert.Equal(t, post1.Time.Unix(), posts[0].(*ForumPost).Time.Unix())
posts, next, err = db.Activity(locale, next, 1, all)
require.NoError(t, err)
require.Equal(t, 1, len(posts))
assert.Equal(t, post2.Id, posts[0].(*ForumPost).Id)
assert.Equal(t, post2.Poster, posts[0].(*ForumPost).Poster)
assert.Equal(t, post2.Time.Unix(), posts[0].(*ForumPost).Time.Unix())
posts, _, err = db.Activity(locale, next, 1, all)
require.NoError(t, err)
require.Equal(t, 0, len(posts))
}