Add unit tests to GetDriverDialect() func

pull/16/head
Vinícius Garcia 2022-01-22 19:11:02 -03:00
parent eded1b5dfd
commit 0776e9f89b
2 changed files with 25 additions and 4 deletions

View File

@ -70,10 +70,7 @@ func (sqlite3Dialect) Placeholder(idx int) string {
// provided driver string, if the drive is not supported
// it returns an error
func GetDriverDialect(driver string) (Dialect, error) {
dialect, found := map[string]Dialect{
"postgres": &postgresDialect{},
"sqlite3": &sqlite3Dialect{},
}[driver]
dialect, found := supportedDialects[driver]
if !found {
return nil, fmt.Errorf("unsupported driver `%s`", driver)
}

24
dialect_test.go Normal file
View File

@ -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")
})
}