-
Notifications
You must be signed in to change notification settings - Fork 117
/
sql_go111_test.go
64 lines (56 loc) · 1.8 KB
/
sql_go111_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
// Copyright 2017-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
// +build go1.11
package xray
import (
"testing"
"github.com/DATA-DOG/go-sqlmock"
"github.com/stretchr/testify/assert"
)
func TestMySQLPasswordConnectionString(t *testing.T) {
tc := []struct {
dsn string
url string
str string
}{
{
dsn: "username:password@protocol(address:1234)/dbname?param=value",
url: "username@protocol(address:1234)/dbname?param=value",
str: "username@protocol(address:1234)/dbname?param=value",
},
{
dsn: "username@protocol(address:1234)/dbname?param=value",
url: "username@protocol(address:1234)/dbname?param=value",
str: "username@protocol(address:1234)/dbname?param=value",
},
}
for _, tt := range tc {
tt := tt
t.Run(tt.dsn, func(t *testing.T) {
db, mock, err := sqlmock.NewWithDSN(tt.dsn)
if err != nil {
t.Fatal(err)
}
defer db.Close()
mockMySQL(mock, nil)
subseg, err := capturePing(tt.dsn)
if err != nil {
t.Fatal(err)
}
assert.NoError(t, mock.ExpectationsWereMet())
assert.Equal(t, "remote", subseg.Namespace)
assert.Equal(t, "MySQL", subseg.SQL.DatabaseType)
if subseg.SQL.URL != "" {
assert.Equal(t, tt.url, subseg.SQL.URL)
}
if subseg.SQL.ConnectionString != "" {
assert.Equal(t, tt.str, subseg.SQL.ConnectionString)
}
})
}
}