-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
driver_test.go
64 lines (59 loc) · 1.32 KB
/
driver_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
package pgxmock
import (
"context"
"testing"
)
func TestTwoOpenConnectionsOnTheSameDSN(t *testing.T) {
mock, err := NewConn()
if err != nil {
t.Fatalf("expected no error, but got: %s", err)
}
mock2, err := NewConn()
if err != nil {
t.Fatalf("expected no error, but got: %s", err)
}
if mock == mock2 {
t.Errorf("expected not the same mock instance, but it is the same")
}
mock.Close(context.Background())
mock2.Close(context.Background())
}
func TestPools(t *testing.T) {
mock, err := NewPool()
if err != nil {
t.Fatalf("expected no error, but got: %s", err)
}
mock2, err := NewPool()
if err != nil {
t.Fatalf("expected no error, but got: %s", err)
}
if mock == mock2 {
t.Errorf("expected not the same mock instance, but it is the same")
}
conn := mock.AsConn()
if conn == nil {
t.Error("expected connection strruct, but got nil")
}
mock.Close()
mock2.Close()
}
func TestAcquire(t *testing.T) {
mock, err := NewPool()
if err != nil {
t.Fatalf("expected no error, but got: %s", err)
}
_, err = mock.Acquire(context.Background())
if err == nil {
t.Error("expected error, but got nil")
}
}
func TestPoolStat(t *testing.T) {
mock, err := NewPool()
if err != nil {
t.Fatalf("expected no error, but got: %s", err)
}
s := mock.Stat()
if s == nil {
t.Error("expected stat object, but got nil")
}
}