-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from pashagolub/102-scan-panics-for-sqlnulltime
[-] fix `Scan()` panic if nullable `sql` types used, fixes #102
- Loading branch information
Showing
3 changed files
with
38 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
min-complexity: 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |