Additional QueryContext and ExecContext tests.

This commit is contained in:
go-jet 2019-07-20 13:33:25 +02:00
parent 8321024989
commit 3fa2220a18
3 changed files with 112 additions and 0 deletions

View file

@ -1,11 +1,13 @@
package tests
import (
"context"
. "github.com/go-jet/jet"
"github.com/go-jet/jet/tests/.gentestdata/jetdb/test_sample/model"
. "github.com/go-jet/jet/tests/.gentestdata/jetdb/test_sample/table"
"gotest.tools/assert"
"testing"
"time"
)
func TestDeleteWithWhere(t *testing.T) {
@ -60,3 +62,38 @@ func initForDeleteTest(t *testing.T) {
assertExec(t, stmt, 2)
}
func TestDeleteQueryContext(t *testing.T) {
initForDeleteTest(t)
deleteStmt := Link.
DELETE().
WHERE(Link.Name.IN(String("Gmail"), String("Outlook")))
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Microsecond)
defer cancel()
time.Sleep(10 * time.Microsecond)
dest := []model.Link{}
err := deleteStmt.QueryContext(ctx, db, &dest)
assert.Error(t, err, "context deadline exceeded")
}
func TestDeleteExecContext(t *testing.T) {
initForDeleteTest(t)
deleteStmt := Link.
DELETE().
WHERE(Link.Name.IN(String("Gmail"), String("Outlook")))
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Microsecond)
defer cancel()
time.Sleep(10 * time.Microsecond)
_, err := deleteStmt.ExecContext(ctx, db)
assert.Error(t, err, "context deadline exceeded")
}