Statements execution with context.
This commit is contained in:
parent
cdfd8f1dff
commit
1ac324e198
11 changed files with 146 additions and 28 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package tests
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
|
|
@ -10,6 +11,7 @@ import (
|
|||
"gotest.tools/assert"
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestSelect(t *testing.T) {
|
||||
|
|
@ -152,6 +154,36 @@ ORDER BY "Album.AlbumId";
|
|||
assert.DeepEqual(t, dest[1], album2)
|
||||
}
|
||||
|
||||
func TestQueryWithContext(t *testing.T) {
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
|
||||
defer cancel()
|
||||
|
||||
dest := []model.Album{}
|
||||
|
||||
err := Album.
|
||||
CROSS_JOIN(Track).
|
||||
CROSS_JOIN(InvoiceLine).
|
||||
SELECT(Album.AllColumns, Track.AllColumns, InvoiceLine.AllColumns).
|
||||
QueryContext(db, ctx, &dest)
|
||||
|
||||
assert.Error(t, err, "context deadline exceeded")
|
||||
}
|
||||
|
||||
func TestExecWithContext(t *testing.T) {
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
|
||||
defer cancel()
|
||||
|
||||
_, err := Album.
|
||||
CROSS_JOIN(Track).
|
||||
CROSS_JOIN(InvoiceLine).
|
||||
SELECT(Album.AllColumns, Track.AllColumns, InvoiceLine.AllColumns).
|
||||
ExecContext(db, ctx)
|
||||
|
||||
assert.Error(t, err, "pq: canceling statement due to user request")
|
||||
}
|
||||
|
||||
func TestSubQueriesForQuotedNames(t *testing.T) {
|
||||
first10Artist := Artist.
|
||||
SELECT(Artist.AllColumns).
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue