-
-
Notifications
You must be signed in to change notification settings - Fork 151
/
Copy pathclient_test.go
123 lines (97 loc) · 3.64 KB
/
client_test.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
* Copyright 2021 The Yorkie Authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package mongo_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/yorkie-team/yorkie/api/types"
"github.com/yorkie-team/yorkie/server/backend/database/mongo"
"github.com/yorkie-team/yorkie/server/backend/database/testcases"
"github.com/yorkie-team/yorkie/test/helper"
)
const (
dummyProjectID = types.ID("000000000000000000000000")
projectOneID = types.ID("000000000000000000000001")
projectTwoID = types.ID("000000000000000000000002")
)
func setupTestWithDummyData(t *testing.T) *mongo.Client {
config := &mongo.Config{
ConnectionTimeout: "5s",
ConnectionURI: "mongodb://localhost:27017",
YorkieDatabase: helper.TestDBName(),
PingTimeout: "5s",
}
assert.NoError(t, config.Validate())
cli, err := mongo.Dial(config)
assert.NoError(t, err)
return cli
}
func TestClient(t *testing.T) {
cli := setupTestWithDummyData(t)
t.Run("FindNextNCyclingProjectInfos test", func(t *testing.T) {
testcases.RunFindNextNCyclingProjectInfosTest(t, cli)
})
t.Run("FindDeactivateCandidatesPerProject test", func(t *testing.T) {
testcases.RunFindDeactivateCandidatesPerProjectTest(t, cli)
})
t.Run("RunFindDocInfo test", func(t *testing.T) {
testcases.RunFindDocInfoTest(t, cli, dummyProjectID)
})
t.Run("RunFindDocInfosByQuery test", func(t *testing.T) {
t.Skip("TODO(hackerwins): the order of docInfos is different with memDB")
testcases.RunFindDocInfosByQueryTest(t, cli, projectOneID)
})
t.Run("RunFindChangesBetweenServerSeqs test", func(t *testing.T) {
testcases.RunFindChangesBetweenServerSeqsTest(t, cli, dummyProjectID)
})
t.Run("RunFindClosestSnapshotInfo test", func(t *testing.T) {
testcases.RunFindClosestSnapshotInfoTest(t, cli, dummyProjectID)
})
t.Run("ListUserInfos test", func(t *testing.T) {
t.Skip("TODO(hackerwins): time is returned as Local")
testcases.RunListUserInfosTest(t, cli)
})
t.Run("FindUserInfoByID test", func(t *testing.T) {
testcases.RunFindUserInfoByIDTest(t, cli)
})
t.Run("FindUserInfoByName test", func(t *testing.T) {
testcases.RunFindUserInfoByNameTest(t, cli)
})
t.Run("FindProjectInfoBySecretKey test", func(t *testing.T) {
testcases.RunFindProjectInfoBySecretKeyTest(t, cli)
})
t.Run("FindProjectInfoByName test", func(t *testing.T) {
testcases.RunFindProjectInfoByNameTest(t, cli)
})
t.Run("ActivateClientDeactivateClient test", func(t *testing.T) {
testcases.RunActivateClientDeactivateClientTest(t, cli, dummyProjectID)
})
t.Run("UpdateProjectInfo test", func(t *testing.T) {
testcases.RunUpdateProjectInfoTest(t, cli)
})
t.Run("FindDocInfosByPaging test", func(t *testing.T) {
testcases.RunFindDocInfosByPagingTest(t, cli, projectTwoID)
})
t.Run("CreateChangeInfo test", func(t *testing.T) {
testcases.RunCreateChangeInfosTest(t, cli, dummyProjectID)
})
t.Run("UpdateClientInfoAfterPushPull test", func(t *testing.T) {
testcases.RunUpdateClientInfoAfterPushPullTest(t, cli, dummyProjectID)
})
t.Run("IsDocumentAttached test", func(t *testing.T) {
testcases.RunIsDocumentAttachedTest(t, cli, dummyProjectID)
})
}