forked from warphq/memongo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
57 lines (47 loc) · 1.51 KB
/
main_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
package strikememongo
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"github.com/strikesecurity/strikememongo/strikememongolog"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/mongo/readpref"
)
func TestDefaultOptions(t *testing.T) {
versions := []string{"3.2.22", "3.4.21", "3.6.13", "4.0.13", "4.2.1", "6.0.3"}
for _, version := range versions {
t.Run(version, func(t *testing.T) {
server, err := StartWithOptions(&Options{
MongoVersion: version,
LogLevel: strikememongolog.LogLevelDebug,
})
require.NoError(t, err)
defer server.Stop()
client, err := mongo.Connect(context.Background(), options.Client().ApplyURI(server.URI()))
require.NoError(t, err)
require.NoError(t, client.Ping(context.Background(), nil))
})
}
}
func TestWithReplica(t *testing.T) {
//versions := []string{"3.6.13", "4.0.13", "4.2.1"}
versions := []string{"4.2.1"}
for _, version := range versions {
t.Run(version, func(t *testing.T) {
server, err := StartWithOptions(&Options{
MongoVersion: version,
LogLevel: strikememongolog.LogLevelDebug,
ShouldUseReplica: true,
})
require.NoError(t, err)
defer server.Stop()
client, err := mongo.Connect(context.Background(), options.Client().ApplyURI(server.URI()))
if err != nil {
server.logger.Warnf("err Connect: %v", err)
}
require.NoError(t, err)
require.NoError(t, client.Ping(context.Background(), readpref.Primary()))
})
}
}