diff --git a/.golangci.yml b/.golangci.yml index 9bb84bd..3cc458b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,20 +1,10 @@ linters: enable: - gocyclo - - golint - - misspell - disable: - - structcheck # too many false positives + - misspell + - revive linters-settings: gocyclo: # minimal code complexity to report, 30 by default (but we recommend 10-20) - min-complexity: 20 - -issues: - # List of regexps of issue texts to exclude, empty list by default. - # But independently from this option we use default exclude patterns, - # it can be disabled by `exclude-use-default: false`. To list all - # excluded by default patterns execute `golangci-lint run --help` - exclude: - - SA5008 # ignore staticcheck for go-flags \ No newline at end of file + min-complexity: 20 \ No newline at end of file diff --git a/rows.go b/rows.go index 8f1c5a4..c716259 100644 --- a/rows.go +++ b/rows.go @@ -95,11 +95,11 @@ func (rs *rowSets) Scan(dest ...interface{}) error { continue } val := reflect.ValueOf(col) - if _, ok := dest[i].(*interface{}); ok || destVal.Elem().Kind() == val.Kind() { + if _, ok := dest[i].(*interface{}); ok || val.Type().AssignableTo(destVal.Elem().Type()) { if destElem := destVal.Elem(); destElem.CanSet() { destElem.Set(val) } else { - return fmt.Errorf("Cannot set destination value for column %s", string(r.defs[i].Name)) + return fmt.Errorf("Cannot set destination value for column %s", string(r.defs[i].Name)) } } else { // Try to use Scanner interface diff --git a/sql_test.go b/sql_test.go new file mode 100644 index 0000000..bf9d382 --- /dev/null +++ b/sql_test.go @@ -0,0 +1,33 @@ +package pgxmock_test + +import ( + "context" + "database/sql" + "testing" + "time" + + pgxmock "github.com/pashagolub/pgxmock/v2" +) + +func TestScanTime(t *testing.T) { + mock, err := pgxmock.NewPool() + if err != nil { + panic(err) + } + + now, _ := time.Parse(time.RFC3339, "2006-01-02T15:04:05Z07:00") + + mock.ExpectQuery(`SELECT now()`). + WillReturnRows( + mock.NewRows([]string{"stamp"}). + AddRow(now)) + + var value sql.NullTime + err = mock.QueryRow(context.Background(), `SELECT now()`).Scan(&value) + if err != nil { + t.Error(err) + } + if value.Time != now { + t.Errorf("want %v, got %v", now, value.Time) + } +}