mirror of
https://github.com/DATA-DOG/go-sqlmock.git
synced 2024-11-24 08:32:36 +02:00
fix
This commit is contained in:
parent
db5c272208
commit
118815aba3
@ -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 \\(\\?,\\?,\\?,\\?\\)"
|
||||||
|
@ -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"))
|
||||||
|
Loading…
Reference in New Issue
Block a user