-
Notifications
You must be signed in to change notification settings - Fork 2
/
dsn_test.go
55 lines (48 loc) · 1.29 KB
/
dsn_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
/*
Copyright © 2024 Acronis International GmbH.
Released under MIT license.
*/
package dbkit
import (
"database/sql"
"testing"
"github.com/stretchr/testify/require"
)
func TestMakeMySQLDSN(t *testing.T) {
cfg := &MySQLConfig{
Host: "myhost",
Port: 3307,
User: "myadmin",
Password: "mypassword",
Database: "mydb",
}
wantDSN := "myadmin:mypassword@tcp(myhost:3307)/mydb?multiStatements=true&parseTime=true&autocommit=false"
gotDSN := MakeMySQLDSN(cfg)
require.Equal(t, wantDSN, gotDSN)
}
func TestMakePgSQLDSN(t *testing.T) {
cfg := &PostgresConfig{
Host: "myhost",
TxIsolationLevel: sql.LevelReadCommitted,
Port: 5432,
User: "myadmin",
Password: "mypassword",
Database: "mydb",
}
wantDSN := "postgres://myadmin:mypassword@myhost:5432/mydb?sslmode=verify-ca"
gotDSN := MakePostgresDSN(cfg)
require.Equal(t, wantDSN, gotDSN)
}
func TestMakeMSSQLDSN(t *testing.T) {
cfg := &MSSQLConfig{
Host: "myhost",
TxIsolationLevel: sql.LevelReadCommitted,
Port: 1433,
User: "myadmin",
Password: "mypassword",
Database: "sysdb",
}
wantDSN := "sqlserver://myadmin:mypassword@myhost:1433?database=sysdb"
gotDSN := MakeMSSQLDSN(cfg)
require.Equal(t, wantDSN, gotDSN)
}