mirror of
https://github.com/zhashkevych/go-sqlxmock.git
synced 2024-11-24 08:12:13 +02:00
fix
This commit is contained in:
parent
db5c272208
commit
118815aba3
@ -4,27 +4,9 @@ package sqlmock
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql/driver"
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type CustomConverter struct{}
|
||||
|
||||
func (s CustomConverter) ConvertValue(v interface{}) (driver.Value, error) {
|
||||
switch v.(type) {
|
||||
case string:
|
||||
return v.(string), nil
|
||||
case []string:
|
||||
return v.([]string), nil
|
||||
case int:
|
||||
return v.(int), nil
|
||||
default:
|
||||
return nil, errors.New(fmt.Sprintf("cannot convert %T with value %v", v, v))
|
||||
}
|
||||
}
|
||||
|
||||
func TestCustomValueConverterExec(t *testing.T) {
|
||||
db, mock, _ := New(ValueConverterOption(CustomConverter{}))
|
||||
expectedQuery := "INSERT INTO tags \\(name,email,age,hobbies\\) VALUES \\(\\?,\\?,\\?,\\?\\)"
|
||||
|
@ -1,11 +1,28 @@
|
||||
package sqlmock
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type CustomConverter struct{}
|
||||
|
||||
func (s CustomConverter) ConvertValue(v interface{}) (driver.Value, error) {
|
||||
switch v.(type) {
|
||||
case string:
|
||||
return v.(string), nil
|
||||
case []string:
|
||||
return v.([]string), nil
|
||||
case int:
|
||||
return v.(int), nil
|
||||
default:
|
||||
return nil, errors.New(fmt.Sprintf("cannot convert %T with value %v", v, v))
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleExpectedExec() {
|
||||
db, mock, _ := New()
|
||||
result := NewErrorResult(fmt.Errorf("some error"))
|
||||
|
Loading…
Reference in New Issue
Block a user