mirror of
https://github.com/VinGarcia/ksql.git
synced 2025-04-27 21:22:42 +00:00
Add unit tests to GetDriverDialect() func
This commit is contained in:
parent
eded1b5dfd
commit
0776e9f89b
@ -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
24
dialect_test.go
Normal 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")
|
||||
})
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user