-
Notifications
You must be signed in to change notification settings - Fork 0
/
mssql_test.go
106 lines (91 loc) · 4.21 KB
/
mssql_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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package mssql
import (
"github.com/go-gdbc/gdbc"
"github.com/stretchr/testify/assert"
"testing"
)
func getDSN(t *testing.T, dataSourceUrl string) (string, error) {
adapter := gdbc.GetDataSourceNameAdapter("sqlserver")
dataSource, err := gdbc.GetDataSource(dataSourceUrl)
assert.Nil(t, err)
return adapter.GetDataSourceName(dataSource)
}
func getDSNWithUser(t *testing.T, dataSourceUrl string, username string, password string) (string, error) {
adapter := gdbc.GetDataSourceNameAdapter("sqlserver")
dataSource, err := gdbc.GetDataSource(dataSourceUrl, gdbc.Username(username), gdbc.Password(password))
assert.Nil(t, err)
return adapter.GetDataSourceName(dataSource)
}
func TestMsSQLDataSourceNameAdapter_GetDataSourceNameWithPort(t *testing.T) {
dsn, err := getDSN(t, "gdbc:sqlserver://username:password@localhost:3000?param1=value¶m2=value")
assert.Nil(t, err)
assert.Contains(t, dsn, "sqlserver://username:password@localhost:3000")
assert.Contains(t, dsn, "param1=value")
assert.Contains(t, dsn, "param2=value")
}
func TestMsSQLDataSourceNameAdapter_GetDataSourceNameWithPortAndWithoutPassword(t *testing.T) {
dsn, err := getDSN(t, "gdbc:sqlserver://username@localhost:3000?param1=value¶m2=value")
assert.Nil(t, err)
assert.Contains(t, dsn, "sqlserver://username@localhost:3000")
assert.Contains(t, dsn, "param1=value")
assert.Contains(t, dsn, "param2=value")
}
func TestMsSQLDataSourceNameAdapter_GetDataSourceNameWithInstance(t *testing.T) {
dsn, err := getDSN(t, "gdbc:sqlserver://username:password@localhost/instanceName?param1=value¶m2=value")
assert.Nil(t, err)
assert.Contains(t, dsn, "sqlserver://username:password@localhost/instanceName")
assert.Contains(t, dsn, "param1=value")
assert.Contains(t, dsn, "param2=value")
}
func TestMsSQLDataSourceNameAdapter_GetDataSourceNameWithWrongInstance(t *testing.T) {
dsn, err := getDSN(t, "gdbc:sqlserver://username:password@localhost/instanceName/test?param1=value¶m2=value")
assert.NotNil(t, err)
assert.Equal(t, "instance format is wrong : instanceName/test", err.Error())
assert.Empty(t, dsn)
}
func TestMsSQLDataSourceNameAdapter_GetDataSourceNameWithInstanceAndWithoutPassword(t *testing.T) {
dsn, err := getDSN(t, "gdbc:sqlserver://username@localhost/instanceName?param1=value¶m2=value")
assert.Nil(t, err)
assert.Contains(t, dsn, "sqlserver://username@localhost/instanceName")
assert.Contains(t, dsn, "param1=value")
assert.Contains(t, dsn, "param2=value")
}
func TestMsSQLDataSourceNameAdapter_GetDataSourceNameWithPortAndWithoutArguments(t *testing.T) {
dsn, err := getDSN(t, "gdbc:sqlserver://username:password@localhost:3000")
assert.Nil(t, err)
assert.Equal(t, dsn, "sqlserver://username:password@localhost:3000")
}
func TestMsSQLDataSourceNameAdapter_GetDataSourceNameWithInstancePortAndWithoutArguments(t *testing.T) {
dsn, err := getDSN(t, "gdbc:sqlserver://username@localhost/instanceName")
assert.Nil(t, err)
assert.Equal(t, dsn, "sqlserver://username@localhost/instanceName")
}
func TestMsSQLDataSourceNameAdapter_GetDataSourceNameWithoutInstanceAndPort(t *testing.T) {
dsn, err := getDSN(t, "gdbc:sqlserver://username@localhost")
assert.NotNil(t, err)
assert.Equal(t, "you need specify port or instance", err.Error())
assert.Empty(t, dsn)
}
func TestMsSQLDataSourceNameAdapter_GetDataSourceNameWithInstanceAndPort(t *testing.T) {
dsn, err := getDSN(t, "gdbc:sqlserver://username@localhost:3000/instance")
assert.NotNil(t, err)
assert.Equal(t, "you need only specify port or instance", err.Error())
assert.Empty(t, dsn)
}
func TestMsSQLDataSourceNameAdapter_GetDataSourceNameWithoutHost(t *testing.T) {
dsn, err := getDSN(t, "gdbc:sqlserver://")
assert.NotNil(t, err)
assert.Equal(t, "host cannot be empty", err.Error())
assert.Empty(t, dsn)
}
func TestMsSQLDataSourceNameAdapter_GetDataSourceNameWithoutUser(t *testing.T) {
dsn, err := getDSN(t, "gdbc:sqlserver://localhost:3000")
assert.NotNil(t, err)
assert.Equal(t, "user cannot be empty", err.Error())
assert.Empty(t, dsn)
}
func TestMsSQLDataSourceNameAdapter_GetDataSourceNameWithUserAndPassword(t *testing.T) {
dsn, err := getDSNWithUser(t, "gdbc:sqlserver://localhost:3000", "username", "password")
assert.Nil(t, err)
assert.Equal(t, dsn, "sqlserver://username:password@localhost:3000")
}