1
0
mirror of https://github.com/DATA-DOG/go-sqlmock.git synced 2024-11-24 08:32:36 +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 ( import (
"context" "context"
"database/sql/driver"
"errors"
"fmt"
"testing" "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) { func TestCustomValueConverterExec(t *testing.T) {
db, mock, _ := New(ValueConverterOption(CustomConverter{})) db, mock, _ := New(ValueConverterOption(CustomConverter{}))
expectedQuery := "INSERT INTO tags \\(name,email,age,hobbies\\) VALUES \\(\\?,\\?,\\?,\\?\\)" expectedQuery := "INSERT INTO tags \\(name,email,age,hobbies\\) VALUES \\(\\?,\\?,\\?,\\?\\)"

View File

@ -1,11 +1,28 @@
package sqlmock package sqlmock
import ( import (
"database/sql/driver"
"errors"
"fmt" "fmt"
"reflect" "reflect"
"testing" "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() { func ExampleExpectedExec() {
db, mock, _ := New() db, mock, _ := New()
result := NewErrorResult(fmt.Errorf("some error")) result := NewErrorResult(fmt.Errorf("some error"))