From 4ad96d717451404d8b4493e946d041cc18376b97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Carlos=20Nieto?= Date: Sat, 13 Jul 2019 15:55:31 +0000 Subject: [PATCH] add test for #508 --- internal/sqladapter/testing/adapter.go.tpl | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/internal/sqladapter/testing/adapter.go.tpl b/internal/sqladapter/testing/adapter.go.tpl index dcec8780..76a2dfb3 100644 --- a/internal/sqladapter/testing/adapter.go.tpl +++ b/internal/sqladapter/testing/adapter.go.tpl @@ -4,6 +4,7 @@ package ADAPTER import ( "database/sql" + "database/sql/driver" "flag" "fmt" "log" @@ -1978,3 +1979,43 @@ func TestCustomType(t *testing.T) { assert.Equal(t, "foo: some name", string(bar.Custom.Val)) } + +type brokenValuer string + +func (b brokenValuer) Value() (driver.Value, error) { + panic("broken valuer") + return nil, nil +} + +// See: https://github.com/upper/db/issues/508 +func TestBrokenValuer(t *testing.T) { + defer func() { + r := recover() + assert.NotNil(t, r, "expecting a panic") + }() + + sess := mustOpen() + + value := brokenValuer("test") + q := sess.Select().From("artist").Where(db.Cond{"name": value}) + + q.Query() +} + +func TestBrokenValuerTx(t *testing.T) { + defer func() { + r := recover() + assert.NotNil(t, r, "expecting a panic") + }() + + sess := mustOpen() + tx, err := sess.NewTx(nil) + defer tx.Close() + + assert.NoError(t, err) + + value := brokenValuer("test") + q := tx.Select().From("artist").Where(db.Cond{"name": value}) + + q.Query() +}