Skip to content

Commit

Permalink
fix: fix ignored scanner.Err() (#4063)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevwan committed Apr 10, 2024
1 parent a66ae0d commit 682460c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion core/stores/sqlx/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func unmarshalRows(v any, scanner rowsScanner, strict bool) error {
return ErrUnsupportedValueType
}

return nil
return scanner.Err()
default:
return ErrUnsupportedValueType
}
Expand Down
14 changes: 7 additions & 7 deletions core/stores/sqlx/stmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,19 +291,19 @@ func TestStmtBreaker(t *testing.T) {
})
}

func TestQueryScanTimeout(t *testing.T) {
func TestQueryRowsScanTimeout(t *testing.T) {
dbtest.RunTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond)
defer cancel()
row := sqlmock.NewRows([]string{"foo"})
rows := sqlmock.NewRows([]string{"foo"})
for i := 0; i < 10000; i++ {
row = row.AddRow("bar" + strconv.Itoa(i))
rows = rows.AddRow("bar" + strconv.Itoa(i))
}
mock.ExpectQuery("any").WillReturnRows(rows)
var val []struct {
Foo int
Bar string
Foo string
}
conn := NewSqlConnFromDB(db)
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond)
defer cancel()
err := conn.QueryRowsCtx(ctx, &val, "any")
assert.ErrorIs(t, err, context.DeadlineExceeded)
})
Expand Down

0 comments on commit 682460c

Please sign in to comment.