Skip to content

Commit

Permalink
CSVColParser: correctly set nil values in Rows
Browse files Browse the repository at this point in the history
  • Loading branch information
IvoGoman committed Aug 9, 2023
1 parent 3476f31 commit fd971de
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions rows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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" {
Expand All @@ -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) {
Expand Down

0 comments on commit fd971de

Please sign in to comment.