-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmongo_test.go
44 lines (36 loc) · 993 Bytes
/
mongo_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
package mongoex
import (
"testing"
"go.mongodb.org/mongo-driver/v2/mongo/readpref"
"gotest.tools/v3/assert"
"gotest.tools/v3/assert/cmp"
"github.com/circleci/ex/testing/testcontext"
)
func TestNew(t *testing.T) {
ctx := testcontext.Background()
cfg := Config{
URI: "mongodb://root:password@localhost:27017",
UseTLS: false,
}
client, err := New(ctx, "connection-test", cfg)
assert.Assert(t, err)
defer func() {
t.Run("Disconnect client", func(t *testing.T) {
err := client.Disconnect(ctx)
assert.Assert(t, err)
})
}()
t.Run("Ping the database", func(t *testing.T) {
err = client.Ping(ctx, readpref.SecondaryPreferred())
assert.Assert(t, err)
})
}
func TestNew_InvalidURLDoesNotLeak(t *testing.T) {
ctx := testcontext.Background()
cfg := Config{
URI: "mongodb://root:]@localhost:27017",
UseTLS: false,
}
_, err := New(ctx, "connection-test", cfg)
assert.Check(t, cmp.Error(err, "mongoex: failed to parse URI: net/url: invalid userinfo"))
}