Skip to content

Commit

Permalink
fix(driver): Extract scheme from DSN using sqlcon.GetDriverName (#156)
Browse files Browse the repository at this point in the history
Closes #145
  • Loading branch information
kaorimatz authored Feb 29, 2020
1 parent 009c4c4 commit 187e289
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
3 changes: 1 addition & 2 deletions driver/registry_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/ory/x/dbal"
"github.com/ory/x/sqlcon"
"github.com/ory/x/urlx"

"github.com/ory/keto/storage"
)
Expand Down Expand Up @@ -76,7 +75,7 @@ func (m *RegistrySQL) StorageManager() storage.Manager {
}

func (m *RegistrySQL) CanHandle(dsn string) bool {
s := dbal.Canonicalize(urlx.ParseOrFatal(m.l, dsn).Scheme)
s := sqlcon.GetDriverName(dsn)
return s == dbal.DriverMySQL || s == dbal.DriverPostgreSQL
}

Expand Down
24 changes: 24 additions & 0 deletions driver/registry_sql_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package driver

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
)

func TestRegistrySQL_CanHandle(t *testing.T) {
for k, tc := range []struct {
dsn string
expected bool
}{
{dsn: "memory"},
{dsn: "mysql://foo:bar@tcp(baz:1234)/db?foo=bar", expected: true},
{dsn: "postgres://foo:bar@baz:1234/db?foo=bar", expected: true},
} {
t.Run(fmt.Sprintf("case=%d", k), func(t *testing.T) {
r := RegistrySQL{}
assert.Equal(t, tc.expected, r.CanHandle(tc.dsn))
})
}
}

0 comments on commit 187e289

Please sign in to comment.