-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconnector_test.go
72 lines (67 loc) · 1.43 KB
/
connector_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
package sparql
import (
"context"
"errors"
"net/http"
"reflect"
"testing"
"time"
"github.com/garsue/sparql/client"
)
func TestNewConnector(t *testing.T) {
opts := []client.Option{
client.WithHTTPClient(&http.Client{
Timeout: 30 * time.Second,
}),
}
want := &Connector{
driver: &Driver{},
Name: "name",
options: opts,
}
if got := NewConnector("name", opts...); !reflect.DeepEqual(got, want) {
t.Errorf("NewConnector() = %+v, want %+v", got, want)
}
}
func TestConnector_Connect(t *testing.T) {
t.Run("error", func(t *testing.T) {
c := &Connector{
driver: nil,
Name: "name",
options: []client.Option{
func(*client.Client) error {
return errors.New("error")
},
},
}
if _, err := c.Connect(context.Background()); err == nil {
t.Errorf("Connector.Connect() error = %v", err)
return
}
})
t.Run("success", func(t *testing.T) {
c := &Connector{
driver: nil,
Name: "name",
options: nil,
}
got, err := c.Connect(context.Background())
if err != nil {
t.Errorf("Connector.Connect() error = %v", err)
return
}
if got, ok := got.(*Conn); ok && got.Client == nil {
t.Errorf("Connector.Connect() = %v", got)
}
})
}
func TestConnector_Driver(t *testing.T) {
c := &Connector{
driver: &Driver{},
Name: "name",
options: nil,
}
if got := c.Driver(); !reflect.DeepEqual(got, c.driver) {
t.Errorf("Connector.Driver() = %v, want %v", got, c.driver)
}
}