database/sql: fail on unsupported options when context is un-cancellable

Currently, the check for `ctx.Done() == context.Background().Done()`
comes before the check to see if we are ignoring any options.  That
check should be done earlier, so that the options are not silently
ignored.

Fixes #21350

Change-Id: I3704e4209854c7d99f3f92498bae831cabc7e419
Reviewed-on: https://go-review.googlesource.com/53970
Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
Run-TryBot: Daniel Theophanes <kardianos@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Matt Dee 2017-08-08 15:58:27 -04:00 committed by Daniel Theophanes
parent d401c427b2
commit bd08803680
2 changed files with 18 additions and 4 deletions

View file

@ -439,6 +439,20 @@ func TestTxContextWait(t *testing.T) {
waitForFree(t, db, 5*time.Second, 0)
}
// TestUnsupportedOptions checks that the database fails when a driver that
// doesn't implement ConnBeginTx is used with non-default options and an
// un-cancellable context.
func TestUnsupportedOptions(t *testing.T) {
db := newTestDB(t, "people")
defer closeDB(t, db)
_, err := db.BeginTx(context.Background(), &TxOptions{
Isolation: LevelSerializable, ReadOnly: true,
})
if err == nil {
t.Fatal("expected error when using unsupported options, got nil")
}
}
func TestMultiResultSetQuery(t *testing.T) {
db := newTestDB(t, "people")
defer closeDB(t, db)