1
0
mirror of https://github.com/zhashkevych/go-sqlxmock.git synced 2024-11-24 08:12:13 +02:00
This commit is contained in:
Nikita Koryabkin 2019-12-02 14:54:33 +03:00
parent db5c272208
commit 118815aba3
2 changed files with 17 additions and 18 deletions

View File

@ -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 \\(\\?,\\?,\\?,\\?\\)"

View File

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