mirror of
https://github.com/neilotoole/sq.git
synced 2024-11-28 03:53:07 +03:00
MySQL DSN no longer strips driver options (#91)
* MySQL DSN no longer strips driver options Fixes #90 * CHANGELOG update
This commit is contained in:
parent
b7cb0a0b66
commit
2d843c9550
@ -1,5 +1,8 @@
|
||||
# CHANGELOG
|
||||
|
||||
## v0.15.3
|
||||
- [#91](https://github.com/neilotoole/sq/pull/91): MySQL driver options no longer stripped
|
||||
|
||||
## v0.15.2
|
||||
- [#89](https://github.com/neilotoole/sq/pull/89): Bug with SQL generated for joins.
|
||||
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/neilotoole/sq/libsq/core/errz"
|
||||
"github.com/neilotoole/sq/libsq/source"
|
||||
)
|
||||
|
||||
var KindFromDBTypeName = kindFromDBTypeName
|
||||
@ -43,3 +44,49 @@ func TestHasErrCode(t *testing.T) {
|
||||
err = errz.Err(err)
|
||||
require.True(t, hasErrCode(err, errNumTableNotExist))
|
||||
}
|
||||
|
||||
func TestDSNFromLocation(t *testing.T) {
|
||||
testCases := []struct {
|
||||
loc string
|
||||
wantDSN string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
loc: "mysql://sakila:p_ssW0rd@localhost:3306/sqtest",
|
||||
wantDSN: "sakila:p_ssW0rd@tcp(localhost:3306)/sqtest",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
loc: "mysql://sakila:p_ssW0rd@localhost:3306/sqtest?allowOldPasswords=1",
|
||||
wantDSN: "sakila:p_ssW0rd@tcp(localhost:3306)/sqtest?allowOldPasswords=1",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
loc: "mysql://sakila:p_ssW0rd@localhost:3306/sqtest?allowCleartextPasswords=true&allowOldPasswords=1",
|
||||
wantDSN: "sakila:p_ssW0rd@tcp(localhost:3306)/sqtest?allowCleartextPasswords=true&allowOldPasswords=1",
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
|
||||
t.Run(tc.loc, func(t *testing.T) {
|
||||
src := &source.Source{
|
||||
Handle: "@testhandle",
|
||||
Type: Type,
|
||||
Location: tc.loc,
|
||||
}
|
||||
|
||||
gotDSN, gotErr := dsnFromLocation(src)
|
||||
if tc.wantErr {
|
||||
require.Error(t, gotErr)
|
||||
return
|
||||
}
|
||||
|
||||
require.NoError(t, gotErr)
|
||||
require.Equal(t, tc.wantDSN, gotDSN)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -405,9 +405,9 @@ func dsnFromLocation(src *source.Source) (string, error) {
|
||||
}
|
||||
|
||||
// Convert the location to the desired driver DSN.
|
||||
// Location: mysql://sakila:p_ssW0rd@localhost:3306/sqtest
|
||||
// Driver DSN: sakila:p_ssW0rd@tcp(localhost:3306)/sqtest
|
||||
driverDSN := fmt.Sprintf("%s@tcp(%s)%s", u.User.String(), u.Host, u.Path)
|
||||
// Location: mysql://sakila:p_ssW0rd@localhost:3306/sqtest?allowOldPasswords=1
|
||||
// Driver DSN: sakila:p_ssW0rd@tcp(localhost:3306)/sqtest?allowOldPasswords=1
|
||||
driverDSN := u.DSN
|
||||
|
||||
_, err = mysql.ParseDSN(driverDSN) // verify
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user