jet/tests/postgres/util_test.go

103 lines
2.2 KiB
Go
Raw Normal View History

2019-07-30 11:45:10 +02:00
package postgres
2019-05-12 18:15:23 +02:00
import (
2019-08-03 14:10:47 +02:00
"github.com/go-jet/jet/internal/jet"
2019-07-29 18:08:53 +02:00
"github.com/go-jet/jet/internal/testutils"
2019-06-24 10:01:34 +02:00
"github.com/go-jet/jet/tests/.gentestdata/jetdb/dvds/model"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
2019-05-12 18:15:23 +02:00
"testing"
)
2019-08-02 11:08:24 +02:00
func AssertExec(t *testing.T, stmt jet.Statement, rowsAffected int64) {
res, err := stmt.Exec(db)
require.NoError(t, err)
rows, err := res.RowsAffected()
assert.NoError(t, err)
assert.Equal(t, rows, rowsAffected)
}
2019-06-21 13:56:57 +02:00
func assertExecErr(t *testing.T, stmt jet.Statement, errorStr string) {
_, err := stmt.Exec(db)
2019-06-21 13:56:57 +02:00
assert.Error(t, err, errorStr)
}
2019-08-13 10:33:31 +02:00
2019-07-29 18:08:53 +02:00
func BoolPtr(b bool) *bool {
return &b
}
2019-07-29 18:08:53 +02:00
func Int16Ptr(i int16) *int16 {
2019-05-12 18:15:23 +02:00
return &i
}
2019-07-29 18:08:53 +02:00
func Int32Ptr(i int32) *int32 {
2019-05-12 18:15:23 +02:00
return &i
}
2019-07-29 18:08:53 +02:00
func Int64Ptr(i int64) *int64 {
return &i
}
2019-07-29 18:08:53 +02:00
func StringPtr(s string) *string {
2019-05-12 18:15:23 +02:00
return &s
}
2019-07-29 18:08:53 +02:00
func ByteArrayPtr(arr []byte) *[]byte {
return &arr
}
2019-07-29 18:08:53 +02:00
func Float32Ptr(f float32) *float32 {
return &f
}
2019-07-29 18:08:53 +02:00
func Float64Ptr(f float64) *float64 {
return &f
}
2019-07-29 18:08:53 +02:00
func UUIDPtr(u string) *uuid.UUID {
2019-06-21 13:56:57 +02:00
newUUID := uuid.MustParse(u)
2019-06-21 13:56:57 +02:00
return &newUUID
}
2019-05-12 18:15:23 +02:00
var customer0 = model.Customer{
CustomerID: 1,
StoreID: 1,
FirstName: "Mary",
LastName: "Smith",
2019-07-29 18:08:53 +02:00
Email: StringPtr("mary.smith@sakilacustomer.org"),
2019-05-20 17:37:55 +02:00
AddressID: 5,
2019-05-12 18:15:23 +02:00
Activebool: true,
2019-07-29 18:08:53 +02:00
CreateDate: *testutils.TimestampWithoutTimeZone("2006-02-14 00:00:00", 0),
LastUpdate: testutils.TimestampWithoutTimeZone("2013-05-26 14:49:45.738", 3),
Active: Int32Ptr(1),
2019-05-12 18:15:23 +02:00
}
var customer1 = model.Customer{
CustomerID: 2,
StoreID: 1,
FirstName: "Patricia",
LastName: "Johnson",
2019-07-29 18:08:53 +02:00
Email: StringPtr("patricia.johnson@sakilacustomer.org"),
2019-05-20 17:37:55 +02:00
AddressID: 6,
2019-05-12 18:15:23 +02:00
Activebool: true,
2019-07-29 18:08:53 +02:00
CreateDate: *testutils.TimestampWithoutTimeZone("2006-02-14 00:00:00", 0),
LastUpdate: testutils.TimestampWithoutTimeZone("2013-05-26 14:49:45.738", 3),
Active: Int32Ptr(1),
2019-05-12 18:15:23 +02:00
}
var lastCustomer = model.Customer{
CustomerID: 599,
StoreID: 2,
FirstName: "Austin",
LastName: "Cintron",
2019-07-29 18:08:53 +02:00
Email: StringPtr("austin.cintron@sakilacustomer.org"),
2019-05-20 17:37:55 +02:00
AddressID: 605,
2019-05-12 18:15:23 +02:00
Activebool: true,
2019-07-29 18:08:53 +02:00
CreateDate: *testutils.TimestampWithoutTimeZone("2006-02-14 00:00:00", 0),
LastUpdate: testutils.TimestampWithoutTimeZone("2013-05-26 14:49:45.738", 3),
Active: Int32Ptr(1),
2019-05-12 18:15:23 +02:00
}