Skip to content

Commit

Permalink
add test for scanning of unknown enum
Browse files Browse the repository at this point in the history
  • Loading branch information
br3w0r committed Mar 31, 2024
1 parent e5f6528 commit 870ab55
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions dbscan/dbscan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,25 @@ func TestScanRow_withAllowUnknownColumns_returnsRow(t *testing.T) {
assert.Equal(t, expected, *got)
}

func TestScanRow_withAllowUnknownColumns_unknownColumnType(t *testing.T) {
t.Parallel()
rows := queryRows(t, `
SELECT 'foo val' AS foo, 'test_val_1'::test_enum_type AS bar
`)
defer rows.Close() //nolint: errcheck
rows.Next()

got := &struct{ Foo string }{}
testAPIWithUnknownColumns, err := getAPI(dbscan.WithAllowUnknownColumns(true))
require.NoError(t, err)
err = testAPIWithUnknownColumns.ScanRow(got, rows)
require.NoError(t, err)
requireNoRowsErrorsAndClose(t, rows)

expected := struct{ Foo string }{Foo: "foo val"}
assert.Equal(t, expected, *got)
}

func TestMain(m *testing.M) {
exitCode := func() int {
flag.Parse()
Expand All @@ -387,6 +406,7 @@ func TestMain(m *testing.M) {
panic(err)
}
defer testDB.Close()
prepareTestDB(testDB)

Check failure on line 409 in dbscan/dbscan_test.go

View workflow job for this annotation

GitHub Actions / lint

Error return value is not checked (errcheck)
testAPI, err = getAPI()
if err != nil {
panic(err)
Expand All @@ -395,3 +415,11 @@ func TestMain(m *testing.M) {
}()
os.Exit(exitCode)
}

func prepareTestDB(testDB *pgxpool.Pool) (err error) {
_, err = testDB.Query(ctx, `

Check failure on line 420 in dbscan/dbscan_test.go

View workflow job for this annotation

GitHub Actions / lint

sqlQuery: ignoring Query() rows result may lead to a connection leak (gocritic)
CREATE TYPE test_enum_type AS ENUM ('test_val_1', 'test_val_2');
`)

return
}

0 comments on commit 870ab55

Please sign in to comment.