-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdsn_test.go
66 lines (55 loc) · 1.46 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
56
57
58
59
60
61
62
63
64
65
66
package migration
import "testing"
func TestDSNBuilderReturnsErrorForUnsupportedDialect(t *testing.T) {
_, err := (&DataSource{Driver: "unsupported"}).String()
if err != ErrUnsupportedDialect {
t.Errorf("Expected %s, got %s", ErrUnsupportedDialect, err)
}
}
func TestToStringSQLite(t *testing.T) {
expected := "file::memory:?cache=shared"
dsn, err := (&DataSource{
Driver: "sqlite",
Name: ":memory:",
Params: "cache=shared",
}).String()
if err != nil {
t.Errorf("Expected error to be nil, got %s", err)
}
if dsn != expected {
t.Errorf("Expected %s, got %s", expected, dsn)
}
}
func TestToStringMySql(t *testing.T) {
expected := "root:password@tcp(localhost:3306)/test?parseTime=true"
dsn, _ := (&DataSource{
Host: "localhost",
Port: "3306",
Username: "root",
Password: "password",
Name: "test",
Params: "parseTime=true",
Driver: "mysql",
}).String()
if dsn != expected {
t.Errorf("Expected %s, got %s", expected, dsn)
}
}
func TestToStringPostgres(t *testing.T) {
expected := "host=localhost port=5432 user=root password=password dbname=test sslmode=disable"
dsn, err := (&DataSource{
Host: "localhost",
Port: "5432",
Username: "root",
Password: "password",
Name: "test",
Params: "sslmode=disable",
Driver: "postgres",
}).String()
if err != nil {
t.Errorf("Expected error to be nil, got %s", err)
}
if dsn != expected {
t.Errorf("Expected dsn to be %s, got %s", expected, dsn)
}
}