mirror of https://github.com/VinGarcia/ksql.git
Add unit tests to GetDriverDialect() func
parent
eded1b5dfd
commit
0776e9f89b
|
@ -70,10 +70,7 @@ func (sqlite3Dialect) Placeholder(idx int) string {
|
||||||
// provided driver string, if the drive is not supported
|
// provided driver string, if the drive is not supported
|
||||||
// it returns an error
|
// it returns an error
|
||||||
func GetDriverDialect(driver string) (Dialect, error) {
|
func GetDriverDialect(driver string) (Dialect, error) {
|
||||||
dialect, found := map[string]Dialect{
|
dialect, found := supportedDialects[driver]
|
||||||
"postgres": &postgresDialect{},
|
|
||||||
"sqlite3": &sqlite3Dialect{},
|
|
||||||
}[driver]
|
|
||||||
if !found {
|
if !found {
|
||||||
return nil, fmt.Errorf("unsupported driver `%s`", driver)
|
return nil, fmt.Errorf("unsupported driver `%s`", driver)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package ksql
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
tt "github.com/vingarcia/ksql/internal/testtools"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetDriverDialect(t *testing.T) {
|
||||||
|
t.Run("should work for all registered drivers", func(t *testing.T) {
|
||||||
|
for drivername, expectedDialect := range supportedDialects {
|
||||||
|
t.Run(drivername, func(t *testing.T) {
|
||||||
|
dialect, err := GetDriverDialect(drivername)
|
||||||
|
tt.AssertNoErr(t, err)
|
||||||
|
tt.AssertEqual(t, dialect, expectedDialect)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("should report error if no driver is found", func(t *testing.T) {
|
||||||
|
_, err := GetDriverDialect("non-existing-driver")
|
||||||
|
tt.AssertErrContains(t, err, "unsupported driver", "non-existing-driver")
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in New Issue