From fd971def423315aacad9923a9a9eb8e4ab86ce11 Mon Sep 17 00:00:00 2001 From: Ivo Gosemann Date: Wed, 9 Aug 2023 17:19:35 +0200 Subject: [PATCH 1/2] CSVColParser: correctly set nil values in Rows --- rows.go | 2 +- rows_test.go | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/rows.go b/rows.go index 24b1bcd..3e916ca 100644 --- a/rows.go +++ b/rows.go @@ -15,7 +15,7 @@ const invalidate = "☠☠☠ MEMORY OVERWRITTEN ☠☠☠ " // CSVColumnParser is a function which converts trimmed csv // column string to a []byte representation. Currently // transforms NULL to nil -var CSVColumnParser = func(s string) []byte { +var CSVColumnParser = func(s string) interface{} { switch { case strings.ToLower(s) == "null": return nil diff --git a/rows_test.go b/rows_test.go index c2a9ebe..3a5afbb 100644 --- a/rows_test.go +++ b/rows_test.go @@ -432,7 +432,7 @@ func TestRowsScanError(t *testing.T) { func TestCSVRowParser(t *testing.T) { t.Parallel() - rs := NewRows([]string{"col1", "col2"}).FromCSVString("a,NULL") + rs := NewRows([]string{"col1", "col2", "col3"}).FromCSVString("a,NULL,NULL") db, mock, err := New() if err != nil { 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() var col1 string var col2 []byte + var col3 *string 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) } if col1 != "a" { @@ -459,6 +460,9 @@ func TestCSVRowParser(t *testing.T) { if col2 != nil { 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) { From 4a9308e2e87ec768ea28c81f46fdf3543454c16c Mon Sep 17 00:00:00 2001 From: IvoGoman Date: Wed, 9 Aug 2023 23:43:51 +0200 Subject: [PATCH 2/2] Update rows_test.go Co-authored-by: Jessie A. Morris --- rows_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rows_test.go b/rows_test.go index 3a5afbb..e2d57ec 100644 --- a/rows_test.go +++ b/rows_test.go @@ -461,7 +461,7 @@ func TestCSVRowParser(t *testing.T) { 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) + t.Fatalf("expected col3 to be nil, but got [%T]:%+v", col3, col3) } }