From 870ab556fa47bdca1fdaba9a39fa6e6bf0bb3f88 Mon Sep 17 00:00:00 2001 From: br3w0r Date: Sun, 31 Mar 2024 18:12:10 +0400 Subject: [PATCH] add test for scanning of unknown enum --- dbscan/dbscan_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/dbscan/dbscan_test.go b/dbscan/dbscan_test.go index c2bd918..5ac0b02 100644 --- a/dbscan/dbscan_test.go +++ b/dbscan/dbscan_test.go @@ -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() @@ -387,6 +406,7 @@ func TestMain(m *testing.M) { panic(err) } defer testDB.Close() + prepareTestDB(testDB) testAPI, err = getAPI() if err != nil { panic(err) @@ -395,3 +415,11 @@ func TestMain(m *testing.M) { }() os.Exit(exitCode) } + +func prepareTestDB(testDB *pgxpool.Pool) (err error) { + _, err = testDB.Query(ctx, ` + CREATE TYPE test_enum_type AS ENUM ('test_val_1', 'test_val_2'); + `) + + return +}