mirror of https://github.com/VinGarcia/ksql.git
Write tests for two trivial functions for raising the test coverage
parent
1e282717b7
commit
6f2ecbef5a
10
ksql.go
10
ksql.go
|
@ -86,16 +86,16 @@ func (c *Config) SetDefaultValues() {
|
||||||
// of the DBAdapter interface
|
// of the DBAdapter interface
|
||||||
func NewWithAdapter(
|
func NewWithAdapter(
|
||||||
db DBAdapter,
|
db DBAdapter,
|
||||||
dbDriver string,
|
dialectName string,
|
||||||
) (DB, error) {
|
) (DB, error) {
|
||||||
dialect := supportedDialects[dbDriver]
|
dialect := supportedDialects[dialectName]
|
||||||
if dialect == nil {
|
if dialect == nil {
|
||||||
return DB{}, fmt.Errorf("unsupported driver `%s`", dbDriver)
|
return DB{}, fmt.Errorf("unsupported driver `%s`", dialectName)
|
||||||
}
|
}
|
||||||
|
|
||||||
return DB{
|
return DB{
|
||||||
dialect: dialect,
|
dialect: dialect,
|
||||||
driver: dbDriver,
|
driver: dialectName,
|
||||||
db: db,
|
db: db,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -441,7 +441,7 @@ func (c DB) insertReturningIDs(
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
if !rows.Next() {
|
if !rows.Next() {
|
||||||
err := fmt.Errorf("unexpected error retrieving the id columns from the database")
|
err := fmt.Errorf("unexpected error when retrieving the id columns from the database")
|
||||||
if rows.Err() != nil {
|
if rows.Err() != nil {
|
||||||
err = rows.Err()
|
err = rows.Err()
|
||||||
}
|
}
|
||||||
|
|
31
ksql_test.go
31
ksql_test.go
|
@ -1896,6 +1896,37 @@ func TestScanRows(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConfigSetDefaultValues(t *testing.T) {
|
||||||
|
config := Config{}
|
||||||
|
config.SetDefaultValues()
|
||||||
|
|
||||||
|
assert.Equal(t, config.MaxOpenConns, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNewAdapterWith(t *testing.T) {
|
||||||
|
t.Run("should build new instances correctly", func(t *testing.T) {
|
||||||
|
for dialectName := range supportedDialects {
|
||||||
|
db, err := NewWithAdapter(
|
||||||
|
DBAdapter(nil),
|
||||||
|
dialectName,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert.Equal(t, nil, err)
|
||||||
|
assert.Equal(t, supportedDialects[dialectName], db.dialect)
|
||||||
|
assert.Equal(t, dialectName, db.driver)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("should report invalid dialectNames correctly", func(t *testing.T) {
|
||||||
|
_, err := NewWithAdapter(
|
||||||
|
DBAdapter(nil),
|
||||||
|
"fake-dialect-name",
|
||||||
|
)
|
||||||
|
|
||||||
|
assert.NotEqual(t, nil, err)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func createTables(driver string) error {
|
func createTables(driver string) error {
|
||||||
connStr := connectionString[driver]
|
connStr := connectionString[driver]
|
||||||
if connStr == "" {
|
if connStr == "" {
|
||||||
|
|
Loading…
Reference in New Issue