forked from jackc/pgx
-
Notifications
You must be signed in to change notification settings - Fork 1
/
conn_config_test.go.example
83 lines (77 loc) · 3.43 KB
/
conn_config_test.go.example
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
package pgx_test
import (
// "crypto/tls"
// "crypto/x509"
// "fmt"
// "go/build"
// "io/ioutil"
// "path"
// "net"
// "time"
"github.com/jackc/pgx"
)
var defaultConnConfig *pgx.ConnConfig = &pgx.ConnConfig{Host: "127.0.0.1", User: "pgx_md5", Password: "secret", Database: "pgx_test"}
// To skip tests for specific connection / authentication types set that connection param to nil
var multihostConnConfig *pgx.ConnConfig = nil
var tcpConnConfig *pgx.ConnConfig = nil
var unixSocketConnConfig *pgx.ConnConfig = nil
var md5ConnConfig *pgx.ConnConfig = nil
var plainPasswordConnConfig *pgx.ConnConfig = nil
var invalidUserConnConfig *pgx.ConnConfig = nil
var tlsConnConfig *pgx.ConnConfig = nil
var customDialerConnConfig *pgx.ConnConfig = nil
var replicationConnConfig *pgx.ConnConfig = nil
var cratedbConnConfig *pgx.ConnConfig = nil
// var multihostConnConfig *pgx.ConnConfig = &pgx.ConnConfig{Host: "2.2.2.2:1,127.0.0.1,4.2.4.2", User: "pgx_md5", Password: "secret", Database: "pgx_test", Dial: (&net.Dialer{KeepAlive: 5 * time.Minute, Timeout: 100 * time.Millisecond}).Dial}
// var tcpConnConfig *pgx.ConnConfig = &pgx.ConnConfig{Host: "127.0.0.1", User: "pgx_md5", Password: "secret", Database: "pgx_test"}
// var unixSocketConnConfig *pgx.ConnConfig = &pgx.ConnConfig{Host: "/private/tmp", User: "pgx_none", Database: "pgx_test"}
// var md5ConnConfig *pgx.ConnConfig = &pgx.ConnConfig{Host: "127.0.0.1", User: "pgx_md5", Password: "secret", Database: "pgx_test"}
// var plainPasswordConnConfig *pgx.ConnConfig = &pgx.ConnConfig{Host: "127.0.0.1", User: "pgx_pw", Password: "secret", Database: "pgx_test"}
// var invalidUserConnConfig *pgx.ConnConfig = &pgx.ConnConfig{Host: "127.0.0.1", User: "invalid", Database: "pgx_test"}
// var customDialerConnConfig *pgx.ConnConfig = &pgx.ConnConfig{Host: "127.0.0.1", User: "pgx_md5", Password: "secret", Database: "pgx_test"}
// var replicationConnConfig *pgx.ConnConfig = &pgx.ConnConfig{Host: "127.0.0.1", User: "pgx_replication", Password: "secret", Database: "pgx_test"}
// var tlsConnConfig *pgx.ConnConfig = &pgx.ConnConfig{Host: "127.0.0.1", User: "pgx_md5", Password: "secret", Database: "pgx_test", TLSConfig: &tls.Config{InsecureSkipVerify: true}}
//
//// or to test client certs:
//
// var tlsConnConfig *pgx.ConnConfig
//
// func init() {
// homeDir := build.Default.GOPATH
// tlsConnConfig = &pgx.ConnConfig{
// Host: "127.0.0.1",
// User: "pgx_md5",
// Password: "secret",
// Database: "pgx_test",
// TLSConfig: &tls.Config{
// InsecureSkipVerify: true,
// },
// }
// caCertPool := x509.NewCertPool()
//
// caPath := path.Join(homeDir, "/src/github.com/jackc/pgx/rootCA.pem")
// caCert, err := ioutil.ReadFile(caPath)
// if err != nil {
// panic(fmt.Sprintf("unable to read CA file: %v", err))
// }
//
// if !caCertPool.AppendCertsFromPEM(caCert) {
// panic("unable to add CA to cert pool")
// }
//
// tlsConnConfig.TLSConfig.RootCAs = caCertPool
// tlsConnConfig.TLSConfig.ClientCAs = caCertPool
//
// sslCert := path.Join(homeDir, "/src/github.com/jackc/pgx/pg_md5.crt")
// sslKey := path.Join(homeDir, "/src/github.com/jackc/pgx/pg_md5.key")
// if (sslCert != "" && sslKey == "") || (sslCert == "" && sslKey != "") {
// panic(`both "sslcert" and "sslkey" are required`)
// }
//
// cert, err := tls.LoadX509KeyPair(sslCert, sslKey)
// if err != nil {
// panic(fmt.Sprintf("unable to read cert: %v", err))
// }
//
// tlsConnConfig.TLSConfig.Certificates = []tls.Certificate{cert}
// }