-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdburl_test.go
37 lines (29 loc) · 1.07 KB
/
dburl_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
package fixture
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestDatabaseURL(t *testing.T) {
rawurl := "mysql://user:password@localhost:1234/test_db?loc=Asia/Shanghai&parseTime=true"
parsedURL, err := Parse(rawurl)
assert.Nil(t, err)
assert.Equal(t, "mysql", parsedURL.Driver())
expectedDSN := "user:password@tcp(localhost:1234)/test_db?loc=Asia%2FShanghai&parseTime=true"
assert.Equal(t, expectedDSN, parsedURL.DSN())
assert.Equal(t, "test_db", parsedURL.DBName())
assert.Equal(t, rawurl, parsedURL.String())
}
func TestDatabaseURL_WithoutDBName(t *testing.T) {
rawurl := "mysql://user:password@localhost:1234?loc=Asia/Shanghai&parseTime=true"
parsedURL, err := Parse(rawurl)
assert.Nil(t, err)
assert.Equal(t, "", parsedURL.DBName())
}
func TestDatabaseURL_Failed(t *testing.T) {
rawurl := "sqlite://user:password@localhost:1234?loc=Asia/Shanghai&parseTime=true"
_, err := Parse(rawurl)
assert.Equal(t, ErrDriverNotSupported, err)
rawurl = "user:password@localhost:1234?loc=Asia/Shanghai&parseTime=true"
_, err = Parse(rawurl)
assert.NotNil(t, err)
}