forked from newrelic/go-agent
/
nrmssql_test.go
67 lines (64 loc) · 1.84 KB
/
nrmssql_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
package nrmssql
import (
"github.com/newrelic/go-agent/v3/newrelic"
"testing"
)
func TestParseDSN(t *testing.T) {
testcases := []struct {
dsn string
expHost string
expPortPathOrID string
expDatabaseName string
}{
// examples from https://github.com/denisenkom/go-mssqldb/blob/master/msdsn/conn_str_test.go
{
dsn: "server=server\\instance;database=testdb;user id=tester;password=pwd",
expHost: "server",
expPortPathOrID: "0",
expDatabaseName: "testdb",
},
{
dsn: "server=(local)",
expHost: "localhost",
expPortPathOrID: "0",
expDatabaseName: "",
},
{
dsn: "sqlserver://someuser@somehost?connection+timeout=30",
expHost: "somehost",
expPortPathOrID: "0",
expDatabaseName: "",
},
{
dsn: "sqlserver://someuser:foo%3A%2F%5C%21~%40;bar@somehost:1434?connection+timeout=30",
expHost: "somehost",
expPortPathOrID: "1434",
expDatabaseName: "",
},
{
dsn: "Server=mssql.test.local; Initial Catalog=test; User ID=xxxxxxx; Password=abccxxxxxx;",
expHost: "mssql.test.local",
expPortPathOrID: "0",
expDatabaseName: "test",
},
{
dsn: "sport=invalid",
expHost: "localhost",
expPortPathOrID: "0",
expDatabaseName: "",
},
}
for _, test := range testcases {
s := &newrelic.DatastoreSegment{}
parseDSN(s, test.dsn)
if test.expHost != s.Host {
t.Errorf(`incorrect host, expected="%s", actual="%s"`, test.expHost, s.Host)
}
if test.expPortPathOrID != s.PortPathOrID {
t.Errorf(`incorrect port path or id, expected="%s", actual="%s"`, test.expPortPathOrID, s.PortPathOrID)
}
if test.expDatabaseName != s.DatabaseName {
t.Errorf(`incorrect database name, expected="%s", actual="%s"`, test.expDatabaseName, s.DatabaseName)
}
}
}