mirror of
https://github.com/DATA-DOG/go-sqlmock.git
synced 2025-03-19 20:57:50 +02:00
CSVColParser: correctly set nil values in Rows
This commit is contained in:
parent
3476f31d8f
commit
fd971def42
2
rows.go
2
rows.go
@ -15,7 +15,7 @@ const invalidate = "☠☠☠ MEMORY OVERWRITTEN ☠☠☠ "
|
|||||||
// CSVColumnParser is a function which converts trimmed csv
|
// CSVColumnParser is a function which converts trimmed csv
|
||||||
// column string to a []byte representation. Currently
|
// column string to a []byte representation. Currently
|
||||||
// transforms NULL to nil
|
// transforms NULL to nil
|
||||||
var CSVColumnParser = func(s string) []byte {
|
var CSVColumnParser = func(s string) interface{} {
|
||||||
switch {
|
switch {
|
||||||
case strings.ToLower(s) == "null":
|
case strings.ToLower(s) == "null":
|
||||||
return nil
|
return nil
|
||||||
|
@ -432,7 +432,7 @@ func TestRowsScanError(t *testing.T) {
|
|||||||
|
|
||||||
func TestCSVRowParser(t *testing.T) {
|
func TestCSVRowParser(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
rs := NewRows([]string{"col1", "col2"}).FromCSVString("a,NULL")
|
rs := NewRows([]string{"col1", "col2", "col3"}).FromCSVString("a,NULL,NULL")
|
||||||
db, mock, err := New()
|
db, mock, err := New()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
|
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
|
||||||
@ -448,9 +448,10 @@ func TestCSVRowParser(t *testing.T) {
|
|||||||
defer rw.Close()
|
defer rw.Close()
|
||||||
var col1 string
|
var col1 string
|
||||||
var col2 []byte
|
var col2 []byte
|
||||||
|
var col3 *string
|
||||||
|
|
||||||
rw.Next()
|
rw.Next()
|
||||||
if err = rw.Scan(&col1, &col2); err != nil {
|
if err = rw.Scan(&col1, &col2, &col3); err != nil {
|
||||||
t.Fatalf("unexpected error: %s", err)
|
t.Fatalf("unexpected error: %s", err)
|
||||||
}
|
}
|
||||||
if col1 != "a" {
|
if col1 != "a" {
|
||||||
@ -459,6 +460,9 @@ func TestCSVRowParser(t *testing.T) {
|
|||||||
if col2 != nil {
|
if col2 != nil {
|
||||||
t.Fatalf("expected col2 to be nil, but got [%T]:%+v", col2, col2)
|
t.Fatalf("expected col2 to be nil, but got [%T]:%+v", col2, col2)
|
||||||
}
|
}
|
||||||
|
if col3 != nil {
|
||||||
|
t.Fatalf("expected col3 to be nil, but got [%T]:%+v", col2, col2)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCSVParserInvalidInput(t *testing.T) {
|
func TestCSVParserInvalidInput(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user