Merge pull request #404 from safaci2000/feature/testTools

Replacing several test util function with a generic version
This commit is contained in:
go-jet 2024-10-07 20:07:55 +02:00 committed by GitHub
commit 31a6b9582a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 161 additions and 214 deletions

View file

@ -4,7 +4,7 @@ import (
"database/sql"
"encoding/json"
"fmt"
"io/ioutil"
"os"
_ "github.com/lib/pq"
@ -90,7 +90,7 @@ func main() {
func jsonSave(path string, v interface{}) {
jsonText, _ := json.MarshalIndent(v, "", "\t")
err := ioutil.WriteFile(path, jsonText, 0644)
err := os.WriteFile(path, jsonText, 0644)
panicOnError(err)
}

View file

@ -12,7 +12,6 @@ import (
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"io/ioutil"
"os"
"path/filepath"
"runtime"
@ -109,7 +108,7 @@ func SaveJSONFile(v interface{}, testRelativePath string) {
jsonText, _ := json.MarshalIndent(v, "", "\t")
filePath := getFullPath(testRelativePath)
err := ioutil.WriteFile(filePath, jsonText, 0644)
err := os.WriteFile(filePath, jsonText, 0644)
throw.OnError(err)
}
@ -118,7 +117,7 @@ func SaveJSONFile(v interface{}, testRelativePath string) {
func AssertJSONFile(t *testing.T, data interface{}, testRelativePath string) {
filePath := getFullPath(testRelativePath)
fileJSONData, err := ioutil.ReadFile(filePath)
fileJSONData, err := os.ReadFile(filePath)
require.NoError(t, err)
if runtime.GOOS == "windows" {
@ -245,7 +244,7 @@ func AssertQueryPanicErr(t *testing.T, stmt jet.Statement, db qrm.DB, dest inter
// AssertFileContent check if file content at filePath contains expectedContent text.
func AssertFileContent(t *testing.T, filePath string, expectedContent string) {
enumFileData, err := ioutil.ReadFile(filePath)
enumFileData, err := os.ReadFile(filePath)
require.NoError(t, err)
@ -254,7 +253,7 @@ func AssertFileContent(t *testing.T, filePath string, expectedContent string) {
// AssertFileNamesEqual check if all filesInfos are contained in fileNames
func AssertFileNamesEqual(t *testing.T, dirPath string, fileNames ...string) {
files, err := ioutil.ReadDir(dirPath)
files, err := os.ReadDir(dirPath)
require.NoError(t, err)
require.Equal(t, len(files), len(fileNames))
@ -293,76 +292,6 @@ func printDiff(actual, expected interface{}, options ...cmp.Option) {
fmt.Println(expected)
}
// BoolPtr returns address of bool parameter
func BoolPtr(b bool) *bool {
return &b
}
// Int8Ptr returns address of int8 parameter
func Int8Ptr(i int8) *int8 {
return &i
}
// UInt8Ptr returns address of uint8 parameter
func UInt8Ptr(i uint8) *uint8 {
return &i
}
// Int16Ptr returns address of int16 parameter
func Int16Ptr(i int16) *int16 {
return &i
}
// UInt16Ptr returns address of uint16 parameter
func UInt16Ptr(i uint16) *uint16 {
return &i
}
// Int32Ptr returns address of int32 parameter
func Int32Ptr(i int32) *int32 {
return &i
}
// UInt32Ptr returns address of uint32 parameter
func UInt32Ptr(i uint32) *uint32 {
return &i
}
// Int64Ptr returns address of int64 parameter
func Int64Ptr(i int64) *int64 {
return &i
}
// UInt64Ptr returns address of uint64 parameter
func UInt64Ptr(i uint64) *uint64 {
return &i
}
// StringPtr returns address of string parameter
func StringPtr(s string) *string {
return &s
}
// TimePtr returns address of time.Time parameter
func TimePtr(t time.Time) *time.Time {
return &t
}
// ByteArrayPtr returns address of []byte parameter
func ByteArrayPtr(arr []byte) *[]byte {
return &arr
}
// Float32Ptr returns address of float32 parameter
func Float32Ptr(f float32) *float32 {
return &f
}
// Float64Ptr returns address of float64 parameter
func Float64Ptr(f float64) *float64 {
return &f
}
// UUIDPtr returns address of uuid.UUID
func UUIDPtr(u string) *uuid.UUID {
newUUID := uuid.MustParse(u)

View file

@ -0,0 +1,6 @@
package ptr
// Of returns the address of any given parameter
func Of[T any](value T) *T {
return &value
}

View file

@ -6,6 +6,8 @@ setup: checkout-testdata docker-compose-up
checkout-testdata:
git submodule init
git submodule update
#
checkout-latest-testdata: checkout-testdata
cd ./testdata && git fetch && git checkout master && git pull
# docker-compose-up will download docker image for each of the databases listed in docker-compose.yaml file, and then it will initialize

View file

@ -13,7 +13,7 @@ services:
- ./testdata/init/postgres:/docker-entrypoint-initdb.d
mysql:
image: mysql:8.0.27
image: mysql:8.0
command: ['--default-authentication-plugin=mysql_native_password', '--log_bin_trust_function_creators=1']
restart: always
environment:

View file

@ -10,7 +10,6 @@ import (
"github.com/go-jet/jet/v2/generator/sqlite"
"github.com/go-jet/jet/v2/internal/utils/errfmt"
"github.com/go-jet/jet/v2/tests/internal/utils/repo"
"io/ioutil"
"os"
"os/exec"
"strings"
@ -184,7 +183,7 @@ func initPostgresDB(dbType string, connectionString string) error {
}
func execFile(db *sql.DB, sqlFilePath string) error {
testSampleSql, err := ioutil.ReadFile(sqlFilePath)
testSampleSql, err := os.ReadFile(sqlFilePath)
if err != nil {
return fmt.Errorf("failed to read sql file - %s: %w", sqlFilePath, err)
}

View file

@ -2,7 +2,6 @@ package file
import (
"github.com/stretchr/testify/require"
"io/ioutil"
"os"
"path"
"testing"
@ -11,7 +10,7 @@ import (
// Exists expects file to exist on path constructed from pathElems and returns content of the file
func Exists(t *testing.T, pathElems ...string) (fileContent string) {
modelFilePath := path.Join(pathElems...)
file, err := ioutil.ReadFile(modelFilePath)
file, err := os.ReadFile(modelFilePath)
require.Nil(t, err)
require.NotEmpty(t, file)
return string(file)
@ -20,6 +19,6 @@ func Exists(t *testing.T, pathElems ...string) (fileContent string) {
// NotExists expects file not to exist on path constructed from pathElems
func NotExists(t *testing.T, pathElems ...string) {
modelFilePath := path.Join(pathElems...)
_, err := ioutil.ReadFile(modelFilePath)
_, err := os.ReadFile(modelFilePath)
require.True(t, os.IsNotExist(err))
}

View file

@ -1,6 +1,7 @@
package mysql
import (
"github.com/go-jet/jet/v2/internal/utils/ptr"
"github.com/shopspring/decimal"
"github.com/stretchr/testify/require"
"strings"
@ -1067,7 +1068,7 @@ func TestAllTypesInsertOnDuplicateKeyUpdate(t *testing.T) {
var toInsert = model.AllTypes{
Boolean: false,
BooleanPtr: testutils.BoolPtr(true),
BooleanPtr: ptr.Of(true),
TinyInt: 1,
UTinyInt: 2,
SmallInt: 3,
@ -1078,53 +1079,53 @@ var toInsert = model.AllTypes{
UInteger: 8,
BigInt: 9,
UBigInt: 1122334455,
TinyIntPtr: testutils.Int8Ptr(11),
UTinyIntPtr: testutils.UInt8Ptr(22),
SmallIntPtr: testutils.Int16Ptr(33),
USmallIntPtr: testutils.UInt16Ptr(44),
MediumIntPtr: testutils.Int32Ptr(55),
UMediumIntPtr: testutils.UInt32Ptr(66),
IntegerPtr: testutils.Int32Ptr(77),
UIntegerPtr: testutils.UInt32Ptr(88),
BigIntPtr: testutils.Int64Ptr(99),
UBigIntPtr: testutils.UInt64Ptr(111),
TinyIntPtr: ptr.Of(int8(11)),
UTinyIntPtr: ptr.Of(uint8(22)),
SmallIntPtr: ptr.Of(int16(33)),
USmallIntPtr: ptr.Of(uint16(44)),
MediumIntPtr: ptr.Of(int32(55)),
UMediumIntPtr: ptr.Of(uint32(66)),
IntegerPtr: ptr.Of(int32(77)),
UIntegerPtr: ptr.Of(uint32(88)),
BigIntPtr: ptr.Of(int64(99)),
UBigIntPtr: ptr.Of(uint64(111)),
Decimal: 11.22,
DecimalPtr: testutils.Float64Ptr(33.44),
DecimalPtr: ptr.Of(33.44),
Numeric: 55.66,
NumericPtr: testutils.Float64Ptr(77.88),
NumericPtr: ptr.Of(77.88),
Float: 99.00,
FloatPtr: testutils.Float64Ptr(11.22),
FloatPtr: ptr.Of(11.22),
Double: 33.44,
DoublePtr: testutils.Float64Ptr(55.66),
DoublePtr: ptr.Of(55.66),
Real: 77.88,
RealPtr: testutils.Float64Ptr(99.00),
RealPtr: ptr.Of(99.00),
Bit: "1",
BitPtr: testutils.StringPtr("0"),
BitPtr: ptr.Of("0"),
Time: time.Date(1, 1, 1, 10, 11, 12, 100, &time.Location{}),
TimePtr: testutils.TimePtr(time.Date(1, 1, 1, 10, 11, 12, 100, time.UTC)),
TimePtr: ptr.Of(time.Date(1, 1, 1, 10, 11, 12, 100, time.UTC)),
Date: time.Now(),
DatePtr: testutils.TimePtr(time.Now()),
DatePtr: ptr.Of(time.Now()),
DateTime: time.Now(),
DateTimePtr: testutils.TimePtr(time.Now()),
DateTimePtr: ptr.Of(time.Now()),
Timestamp: time.Now(),
//TimestampPtr: testutils.TimePtr(time.Now()), // TODO: build fails for MariaDB
Year: 2000,
YearPtr: testutils.Int16Ptr(2001),
YearPtr: ptr.Of(int16(2001)),
Char: "abcd",
CharPtr: testutils.StringPtr("absd"),
CharPtr: ptr.Of("absd"),
VarChar: "abcd",
VarCharPtr: testutils.StringPtr("absd"),
VarCharPtr: ptr.Of("absd"),
Binary: []byte("1010"),
BinaryPtr: testutils.ByteArrayPtr([]byte("100001")),
BinaryPtr: ptr.Of([]byte("100001")),
VarBinary: []byte("1010"),
VarBinaryPtr: testutils.ByteArrayPtr([]byte("100001")),
VarBinaryPtr: ptr.Of([]byte("100001")),
Blob: []byte("large file"),
BlobPtr: testutils.ByteArrayPtr([]byte("very large file")),
BlobPtr: ptr.Of([]byte("very large file")),
Text: "some text",
TextPtr: testutils.StringPtr("text"),
TextPtr: ptr.Of("text"),
Enum: model.AllTypesEnum_Value1,
JSON: "{}",
JSONPtr: testutils.StringPtr(`{"a": 1}`),
JSONPtr: ptr.Of(`{"a": 1}`),
}
var allTypesJson = `
@ -1358,17 +1359,17 @@ func TestExactDecimals(t *testing.T) {
Floats: model.Floats{
// overwritten by wrapped(floats) scope
Numeric: 0.1,
NumericPtr: testutils.Float64Ptr(0.1),
NumericPtr: ptr.Of(0.1),
Decimal: 0.1,
DecimalPtr: testutils.Float64Ptr(0.1),
DecimalPtr: ptr.Of(0.1),
// not overwritten
Float: 0.2,
FloatPtr: testutils.Float64Ptr(0.22),
FloatPtr: ptr.Of(0.22),
Double: 0.3,
DoublePtr: testutils.Float64Ptr(0.33),
DoublePtr: ptr.Of(0.33),
Real: 0.4,
RealPtr: testutils.Float64Ptr(0.44),
RealPtr: ptr.Of(0.44),
},
Numeric: decimal.RequireFromString("12.35"),
NumericPtr: decimal.RequireFromString("56.79"),

View file

@ -4,9 +4,11 @@ import (
"context"
"database/sql"
"github.com/go-jet/jet/v2/internal/testutils"
"github.com/go-jet/jet/v2/internal/utils/ptr"
. "github.com/go-jet/jet/v2/mysql"
"github.com/go-jet/jet/v2/tests/.gentestdata/mysql/test_sample/model"
. "github.com/go-jet/jet/v2/tests/.gentestdata/mysql/test_sample/table"
"github.com/stretchr/testify/require"
"math/rand"
"testing"
@ -300,7 +302,7 @@ func TestInsertOnDuplicateKeyUpdateNEW(t *testing.T) {
ID: randId,
URL: "https://www.yahoo.com",
Name: "Yahoo",
Description: testutils.StringPtr("web portal and search engine"),
Description: ptr.Of("web portal and search engine"),
},
}).AS_NEW().
ON_DUPLICATE_KEY_UPDATE(
@ -337,7 +339,7 @@ ON DUPLICATE KEY UPDATE id = (link.id + ?),
ID: randId + 11,
URL: "https://www.yahoo.com",
Name: "Yahoo",
Description: testutils.StringPtr("web portal and search engine"),
Description: ptr.Of("web portal and search engine"),
})
})
}

View file

@ -2,6 +2,7 @@ package postgres
import (
"database/sql"
"github.com/go-jet/jet/v2/internal/utils/ptr"
"testing"
"time"
@ -1305,32 +1306,32 @@ RETURNING all_types.json AS "all_types.json";
var moodSad = model.Mood_Sad
var allTypesRow0 = model.AllTypes{
SmallIntPtr: testutils.Int16Ptr(14),
SmallIntPtr: ptr.Of(int16(14)),
SmallInt: 14,
IntegerPtr: testutils.Int32Ptr(300),
IntegerPtr: ptr.Of(int32(300)),
Integer: 300,
BigIntPtr: testutils.Int64Ptr(50000),
BigIntPtr: ptr.Of(int64(50000)),
BigInt: 5000,
DecimalPtr: testutils.Float64Ptr(1.11),
DecimalPtr: ptr.Of(1.11),
Decimal: 1.11,
NumericPtr: testutils.Float64Ptr(2.22),
NumericPtr: ptr.Of(2.22),
Numeric: 2.22,
RealPtr: testutils.Float32Ptr(5.55),
RealPtr: ptr.Of(float32(5.55)),
Real: 5.55,
DoublePrecisionPtr: testutils.Float64Ptr(11111111.22),
DoublePrecisionPtr: ptr.Of(11111111.22),
DoublePrecision: 11111111.22,
Smallserial: 1,
Serial: 1,
Bigserial: 1,
//MoneyPtr: nil,
//Money:
VarCharPtr: testutils.StringPtr("ABBA"),
VarCharPtr: ptr.Of("ABBA"),
VarChar: "ABBA",
CharPtr: testutils.StringPtr("JOHN "),
CharPtr: ptr.Of("JOHN "),
Char: "JOHN ",
TextPtr: testutils.StringPtr("Some text"),
TextPtr: ptr.Of("Some text"),
Text: "Some text",
ByteaPtr: testutils.ByteArrayPtr([]byte("bytea")),
ByteaPtr: ptr.Of([]byte("bytea")),
Bytea: []byte("bytea"),
TimestampzPtr: testutils.TimestampWithTimeZone("1999-01-08 13:05:06 +0100 CET", 0),
Timestampz: *testutils.TimestampWithTimeZone("1999-01-08 13:05:06 +0100 CET", 0),
@ -1342,31 +1343,31 @@ var allTypesRow0 = model.AllTypes{
Timez: *testutils.TimeWithTimeZone("04:05:06 -0800"),
TimePtr: testutils.TimeWithoutTimeZone("04:05:06"),
Time: *testutils.TimeWithoutTimeZone("04:05:06"),
IntervalPtr: testutils.StringPtr("3 days 04:05:06"),
IntervalPtr: ptr.Of("3 days 04:05:06"),
Interval: "3 days 04:05:06",
BooleanPtr: testutils.BoolPtr(true),
BooleanPtr: ptr.Of(true),
Boolean: false,
PointPtr: testutils.StringPtr("(2,3)"),
BitPtr: testutils.StringPtr("101"),
PointPtr: ptr.Of("(2,3)"),
BitPtr: ptr.Of("101"),
Bit: "101",
BitVaryingPtr: testutils.StringPtr("101111"),
BitVaryingPtr: ptr.Of("101111"),
BitVarying: "101111",
TsvectorPtr: testutils.StringPtr("'supernova':1"),
TsvectorPtr: ptr.Of("'supernova':1"),
Tsvector: "'supernova':1",
UUIDPtr: testutils.UUIDPtr("a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11"),
UUID: uuid.MustParse("a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11"),
XMLPtr: testutils.StringPtr("<Sub>abc</Sub>"),
XMLPtr: ptr.Of("<Sub>abc</Sub>"),
XML: "<Sub>abc</Sub>",
JSONPtr: testutils.StringPtr(`{"a": 1, "b": 3}`),
JSONPtr: ptr.Of(`{"a": 1, "b": 3}`),
JSON: `{"a": 1, "b": 3}`,
JsonbPtr: testutils.StringPtr(`{"a": 1, "b": 3}`),
JsonbPtr: ptr.Of(`{"a": 1, "b": 3}`),
Jsonb: `{"a": 1, "b": 3}`,
IntegerArrayPtr: testutils.StringPtr("{1,2,3}"),
IntegerArrayPtr: ptr.Of("{1,2,3}"),
IntegerArray: "{1,2,3}",
TextArrayPtr: testutils.StringPtr("{breakfast,consulting}"),
TextArrayPtr: ptr.Of("{breakfast,consulting}"),
TextArray: "{breakfast,consulting}",
JsonbArray: `{"{\"a\": 1, \"b\": 2}","{\"a\": 3, \"b\": 4}"}`,
TextMultiDimArrayPtr: testutils.StringPtr("{{meeting,lunch},{training,presentation}}"),
TextMultiDimArrayPtr: ptr.Of("{{meeting,lunch},{training,presentation}}"),
TextMultiDimArray: "{{meeting,lunch},{training,presentation}}",
MoodPtr: &moodSad,
Mood: model.Mood_Happy,

View file

@ -3,6 +3,7 @@ package postgres
import (
"context"
"github.com/go-jet/jet/v2/internal/testutils"
"github.com/go-jet/jet/v2/internal/utils/ptr"
. "github.com/go-jet/jet/v2/postgres"
"github.com/go-jet/jet/v2/tests/.gentestdata/jetdb/chinook/model"
. "github.com/go-jet/jet/v2/tests/.gentestdata/jetdb/chinook/table"
@ -455,7 +456,7 @@ FROM (
require.Len(t, dest, 275)
require.Equal(t, dest[0].Artist1.Artist, model.Artist{
ArtistId: 1,
Name: testutils.StringPtr("AC/DC"),
Name: ptr.Of("AC/DC"),
})
require.Equal(t, dest[0].Artist1.CustomColumn1, "custom_column_1")
require.Equal(t, dest[0].Artist1.CustomColumn2, "custom_column_2")

View file

@ -2,6 +2,7 @@ package postgres
import (
"database/sql"
"github.com/go-jet/jet/v2/internal/utils/ptr"
"github.com/google/uuid"
"testing"
@ -63,15 +64,15 @@ func TestExactDecimals(t *testing.T) {
Floats: model.Floats{
// overwritten by wrapped(floats) scope
Numeric: 0.1,
NumericPtr: testutils.Float64Ptr(0.1),
NumericPtr: ptr.Of(0.1),
Decimal: 0.1,
DecimalPtr: testutils.Float64Ptr(0.1),
DecimalPtr: ptr.Of(0.1),
// not overwritten
Real: 0.4,
RealPtr: testutils.Float32Ptr(0.44),
RealPtr: ptr.Of(float32(0.44)),
Double: 0.3,
DoublePtr: testutils.Float64Ptr(0.33),
DoublePtr: ptr.Of(0.33),
},
Numeric: decimal.RequireFromString("0.1234567890123456789"),
NumericPtr: decimal.RequireFromString("1.1111111111111111111"),
@ -378,7 +379,7 @@ ORDER BY employee.employee_id;
FirstName: "Salley",
LastName: "Lester",
EmploymentDate: testutils.TimestampWithTimeZone("1999-01-08 04:05:06 +0100 CET", 1),
ManagerID: testutils.Int32Ptr(3),
ManagerID: ptr.Of(int32(3)),
})
}
@ -420,7 +421,7 @@ FROM test_sample."WEIRD NAMES TABLE";
WeirdColumnName5: "Doe",
WeirdColumnName6: "Doe",
WeirdColumnName7: "Doe",
Weirdcolumnname8: testutils.StringPtr("Doe"),
Weirdcolumnname8: ptr.Of("Doe"),
WeirdColName9: "Doe",
WeirdColuName10: "Doe",
WeirdColuName11: "Doe",
@ -518,7 +519,7 @@ func TestMutableColumnsExcludeGeneratedColumn(t *testing.T) {
).MODEL(
model.People{
PeopleName: "Dario",
PeopleHeightCm: testutils.Float64Ptr(120),
PeopleHeightCm: ptr.Of(120.0),
},
).RETURNING(
People.MutableColumns,

View file

@ -2,6 +2,7 @@ package postgres
import (
"context"
"github.com/go-jet/jet/v2/internal/utils/ptr"
"github.com/volatiletech/null/v8"
"testing"
"time"
@ -93,7 +94,7 @@ func TestScanToValidDestination(t *testing.T) {
err := oneInventoryQuery.Query(db, &dest)
require.NoError(t, err)
require.Equal(t, dest[0], testutils.Int32Ptr(1))
require.Equal(t, dest[0], ptr.Of(int32(1)))
})
t.Run("NULL to integer", func(t *testing.T) {
@ -530,10 +531,10 @@ func TestScanToSlice(t *testing.T) {
require.NoError(t, err)
require.Equal(t, len(dest), 2)
testutils.AssertDeepEqual(t, dest[0].Film, film1)
testutils.AssertDeepEqual(t, dest[0].IDs, []*int32{testutils.Int32Ptr(1), testutils.Int32Ptr(2), testutils.Int32Ptr(3), testutils.Int32Ptr(4),
testutils.Int32Ptr(5), testutils.Int32Ptr(6), testutils.Int32Ptr(7), testutils.Int32Ptr(8)})
testutils.AssertDeepEqual(t, dest[0].IDs, []*int32{ptr.Of(int32(1)), ptr.Of(int32(2)), ptr.Of(int32(3)), ptr.Of(int32(4)),
ptr.Of(int32(5)), ptr.Of(int32(6)), ptr.Of(int32(7)), ptr.Of(int32(8))})
testutils.AssertDeepEqual(t, dest[1].Film, film2)
testutils.AssertDeepEqual(t, dest[1].IDs, []*int32{testutils.Int32Ptr(9), testutils.Int32Ptr(10)})
testutils.AssertDeepEqual(t, dest[1].IDs, []*int32{ptr.Of(int32(9)), ptr.Of(int32(10))})
})
t.Run("complex struct 1", func(t *testing.T) {
@ -1076,10 +1077,10 @@ VALUES (1234, 0, 'Joe', '', NULL, 1, TRUE, '2020-02-02 10:00:00Z', NULL, 1);
var address256 = model.Address{
AddressID: 256,
Address: "1497 Yuzhou Drive",
Address2: testutils.StringPtr(""),
Address2: ptr.Of(""),
District: "England",
CityID: 312,
PostalCode: testutils.StringPtr("3433"),
PostalCode: ptr.Of("3433"),
Phone: "246810237916",
LastUpdate: *testutils.TimestampWithoutTimeZone("2006-02-15 09:45:30", 0),
}
@ -1087,10 +1088,10 @@ var address256 = model.Address{
var addres517 = model.Address{
AddressID: 517,
Address: "548 Uruapan Street",
Address2: testutils.StringPtr(""),
Address2: ptr.Of(""),
District: "Ontario",
CityID: 312,
PostalCode: testutils.StringPtr("35653"),
PostalCode: ptr.Of("35653"),
Phone: "879347453467",
LastUpdate: *testutils.TimestampWithoutTimeZone("2006-02-15 09:45:30", 0),
}
@ -1100,12 +1101,12 @@ var customer256 = model.Customer{
StoreID: 2,
FirstName: "Mattie",
LastName: "Hoffman",
Email: testutils.StringPtr("mattie.hoffman@sakilacustomer.org"),
Email: ptr.Of("mattie.hoffman@sakilacustomer.org"),
AddressID: 256,
Activebool: true,
CreateDate: *testutils.TimestampWithoutTimeZone("2006-02-14 00:00:00", 0),
LastUpdate: testutils.TimestampWithoutTimeZone("2013-05-26 14:49:45.738", 0),
Active: testutils.Int32Ptr(1),
Active: ptr.Of(int32(1)),
}
var customer512 = model.Customer{
@ -1113,12 +1114,12 @@ var customer512 = model.Customer{
StoreID: 1,
FirstName: "Cecil",
LastName: "Vines",
Email: testutils.StringPtr("cecil.vines@sakilacustomer.org"),
Email: ptr.Of("cecil.vines@sakilacustomer.org"),
AddressID: 517,
Activebool: true,
CreateDate: *testutils.TimestampWithoutTimeZone("2006-02-14 00:00:00", 0),
LastUpdate: testutils.TimestampWithoutTimeZone("2013-05-26 14:49:45.738", 0),
Active: testutils.Int32Ptr(1),
Active: ptr.Of(int32(1)),
}
var countryUk = model.Country{
@ -1151,32 +1152,32 @@ var inventory2 = model.Inventory{
var film1 = model.Film{
FilmID: 1,
Title: "Academy Dinosaur",
Description: testutils.StringPtr("A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies"),
ReleaseYear: testutils.Int32Ptr(2006),
Description: ptr.Of("A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies"),
ReleaseYear: ptr.Of(int32(2006)),
LanguageID: 1,
RentalDuration: 6,
RentalRate: 0.99,
Length: testutils.Int16Ptr(86),
Length: ptr.Of(int16(86)),
ReplacementCost: 20.99,
Rating: &pgRating,
LastUpdate: *testutils.TimestampWithoutTimeZone("2013-05-26 14:50:58.951", 3),
SpecialFeatures: testutils.StringPtr("{\"Deleted Scenes\",\"Behind the Scenes\"}"),
SpecialFeatures: ptr.Of("{\"Deleted Scenes\",\"Behind the Scenes\"}"),
Fulltext: "'academi':1 'battl':15 'canadian':20 'dinosaur':2 'drama':5 'epic':4 'feminist':8 'mad':11 'must':14 'rocki':21 'scientist':12 'teacher':17",
}
var film2 = model.Film{
FilmID: 2,
Title: "Ace Goldfinger",
Description: testutils.StringPtr("A Astounding Epistle of a Database Administrator And a Explorer who must Find a Car in Ancient China"),
ReleaseYear: testutils.Int32Ptr(2006),
Description: ptr.Of("A Astounding Epistle of a Database Administrator And a Explorer who must Find a Car in Ancient China"),
ReleaseYear: ptr.Of(int32(2006)),
LanguageID: 1,
RentalDuration: 3,
RentalRate: 4.99,
Length: testutils.Int16Ptr(48),
Length: ptr.Of(int16(48)),
ReplacementCost: 12.99,
Rating: &gRating,
LastUpdate: *testutils.TimestampWithoutTimeZone("2013-05-26 14:50:58.951", 3),
SpecialFeatures: testutils.StringPtr(`{Trailers,"Deleted Scenes"}`),
SpecialFeatures: ptr.Of(`{Trailers,"Deleted Scenes"}`),
Fulltext: `'ace':1 'administr':9 'ancient':19 'astound':4 'car':17 'china':20 'databas':8 'epistl':5 'explor':12 'find':15 'goldfing':2 'must':14`,
}

View file

@ -3,6 +3,7 @@ package postgres
import (
"context"
"database/sql"
"github.com/go-jet/jet/v2/internal/utils/ptr"
"testing"
"time"
@ -1828,16 +1829,16 @@ ORDER BY film.film_id ASC;
testutils.AssertDeepEqual(t, maxRentalRateFilms[0], model.Film{
FilmID: 2,
Title: "Ace Goldfinger",
Description: testutils.StringPtr("A Astounding Epistle of a Database Administrator And a Explorer who must Find a Car in Ancient China"),
ReleaseYear: testutils.Int32Ptr(2006),
Description: ptr.Of("A Astounding Epistle of a Database Administrator And a Explorer who must Find a Car in Ancient China"),
ReleaseYear: ptr.Of(int32(2006)),
LanguageID: 1,
RentalRate: 4.99,
Length: testutils.Int16Ptr(48),
Length: ptr.Of(int16(48)),
ReplacementCost: 12.99,
Rating: &gRating,
RentalDuration: 3,
LastUpdate: *testutils.TimestampWithoutTimeZone("2013-05-26 14:50:58.951", 3),
SpecialFeatures: testutils.StringPtr("{Trailers,\"Deleted Scenes\"}"),
SpecialFeatures: ptr.Of("{Trailers,\"Deleted Scenes\"}"),
Fulltext: "'ace':1 'administr':9 'ancient':19 'astound':4 'car':17 'china':20 'databas':8 'epistl':5 'explor':12 'find':15 'goldfing':2 'must':14",
})
}
@ -2286,11 +2287,11 @@ ORDER BY customer_payment_sum.amount_sum ASC;
FirstName: "Brian",
LastName: "Wyman",
AddressID: 323,
Email: testutils.StringPtr("brian.wyman@sakilacustomer.org"),
Email: ptr.Of("brian.wyman@sakilacustomer.org"),
Activebool: true,
CreateDate: *testutils.TimestampWithoutTimeZone("2006-02-14 00:00:00", 0),
LastUpdate: testutils.TimestampWithoutTimeZone("2013-05-26 14:49:45.738", 3),
Active: testutils.Int32Ptr(1),
Active: ptr.Of(int32(1)),
})
require.Equal(t, customersWithAmounts[0].AmountSum, 27.93)
@ -3133,8 +3134,8 @@ func TestDynamicCondition(t *testing.T) {
Active *bool
}
request.CustomerID = testutils.Int64Ptr(1)
request.Active = testutils.BoolPtr(true)
request.CustomerID = ptr.Of(int64(1))
request.Active = ptr.Of(true)
// ...
@ -3894,12 +3895,12 @@ var customer0 = model.Customer{
StoreID: 1,
FirstName: "Mary",
LastName: "Smith",
Email: testutils.StringPtr("mary.smith@sakilacustomer.org"),
Email: ptr.Of("mary.smith@sakilacustomer.org"),
AddressID: 5,
Activebool: true,
CreateDate: *testutils.TimestampWithoutTimeZone("2006-02-14 00:00:00", 0),
LastUpdate: testutils.TimestampWithoutTimeZone("2013-05-26 14:49:45.738", 3),
Active: testutils.Int32Ptr(1),
Active: ptr.Of(int32(1)),
}
var customer1 = model.Customer{
@ -3907,12 +3908,12 @@ var customer1 = model.Customer{
StoreID: 1,
FirstName: "Patricia",
LastName: "Johnson",
Email: testutils.StringPtr("patricia.johnson@sakilacustomer.org"),
Email: ptr.Of("patricia.johnson@sakilacustomer.org"),
AddressID: 6,
Activebool: true,
CreateDate: *testutils.TimestampWithoutTimeZone("2006-02-14 00:00:00", 0),
LastUpdate: testutils.TimestampWithoutTimeZone("2013-05-26 14:49:45.738", 3),
Active: testutils.Int32Ptr(1),
Active: ptr.Of(int32(1)),
}
var lastCustomer = model.Customer{
@ -3920,10 +3921,10 @@ var lastCustomer = model.Customer{
StoreID: 2,
FirstName: "Austin",
LastName: "Cintron",
Email: testutils.StringPtr("austin.cintron@sakilacustomer.org"),
Email: ptr.Of("austin.cintron@sakilacustomer.org"),
AddressID: 605,
Activebool: true,
CreateDate: *testutils.TimestampWithoutTimeZone("2006-02-14 00:00:00", 0),
LastUpdate: testutils.TimestampWithoutTimeZone("2013-05-26 14:49:45.738", 3),
Active: testutils.Int32Ptr(1),
Active: ptr.Of(int32(1)),
}

View file

@ -2,6 +2,7 @@ package sqlite
import (
"github.com/go-jet/jet/v2/internal/testutils"
"github.com/go-jet/jet/v2/internal/utils/ptr"
. "github.com/go-jet/jet/v2/sqlite"
"github.com/go-jet/jet/v2/tests/.gentestdata/sqlite/test_sample/model"
. "github.com/go-jet/jet/v2/tests/.gentestdata/sqlite/test_sample/table"
@ -153,43 +154,43 @@ func TestAllTypesInsert(t *testing.T) {
var toInsert = model.AllTypes{
Boolean: false,
BooleanPtr: testutils.BoolPtr(true),
BooleanPtr: ptr.Of(true),
TinyInt: 1,
SmallInt: 3,
MediumInt: 5,
Integer: 7,
BigInt: 9,
TinyIntPtr: testutils.Int8Ptr(11),
SmallIntPtr: testutils.Int16Ptr(33),
MediumIntPtr: testutils.Int32Ptr(55),
IntegerPtr: testutils.Int32Ptr(77),
BigIntPtr: testutils.Int64Ptr(99),
TinyIntPtr: ptr.Of(int8(11)),
SmallIntPtr: ptr.Of(int16(33)),
MediumIntPtr: ptr.Of(int32(55)),
IntegerPtr: ptr.Of(int32(77)),
BigIntPtr: ptr.Of(int64(99)),
Decimal: 11.22,
DecimalPtr: testutils.Float64Ptr(33.44),
DecimalPtr: ptr.Of(33.44),
Numeric: 55.66,
NumericPtr: testutils.Float64Ptr(77.88),
NumericPtr: ptr.Of(77.88),
Float: 99.00,
FloatPtr: testutils.Float64Ptr(11.22),
FloatPtr: ptr.Of(11.22),
Double: 33.44,
DoublePtr: testutils.Float64Ptr(55.66),
DoublePtr: ptr.Of(55.66),
Real: 77.88,
RealPtr: testutils.Float32Ptr(99.00),
RealPtr: ptr.Of(float32(99.00)),
Time: time.Date(1, 1, 1, 1, 1, 1, 10, time.UTC),
TimePtr: testutils.TimePtr(time.Date(2, 2, 2, 2, 2, 2, 200, time.UTC)),
TimePtr: ptr.Of(time.Date(2, 2, 2, 2, 2, 2, 200, time.UTC)),
Date: time.Now(),
DatePtr: testutils.TimePtr(time.Now()),
DatePtr: ptr.Of(time.Now()),
DateTime: time.Now(),
DateTimePtr: testutils.TimePtr(time.Now()),
DateTimePtr: ptr.Of(time.Now()),
Timestamp: time.Now(),
TimestampPtr: testutils.TimePtr(time.Now()),
TimestampPtr: ptr.Of(time.Now()),
Char: "abcd",
CharPtr: testutils.StringPtr("absd"),
CharPtr: ptr.Of("absd"),
VarChar: "abcd",
VarCharPtr: testutils.StringPtr("absd"),
VarCharPtr: ptr.Of("absd"),
Blob: []byte("large file"),
BlobPtr: testutils.ByteArrayPtr([]byte("very large file")),
BlobPtr: ptr.Of([]byte("very large file")),
Text: "some text",
TextPtr: testutils.StringPtr("text"),
TextPtr: ptr.Of("text"),
}
func TestUUID(t *testing.T) {
@ -659,7 +660,7 @@ func TestExactDecimals(t *testing.T) {
// not overwritten
Numeric: "6.7",
NumericPtr: testutils.StringPtr("7.7"),
NumericPtr: ptr.Of("7.7"),
},
Decimal: decimal.RequireFromString("91.23"),
DecimalPtr: decimal.RequireFromString("45.67"),

View file

@ -3,6 +3,7 @@ package sqlite
import (
"context"
"database/sql"
"github.com/go-jet/jet/v2/internal/utils/ptr"
"math/rand"
"testing"
@ -49,7 +50,7 @@ VALUES (?, ?, ?, ?),
ID: 101,
URL: "http://www.google.com",
Name: "Google",
Description: testutils.StringPtr("Search engine"),
Description: ptr.Of("Search engine"),
})
testutils.AssertDeepEqual(t, insertedLinks[2], model.Link{
ID: 102,

View file

@ -3,6 +3,7 @@ package sqlite
import (
"database/sql"
"github.com/go-jet/jet/v2/internal/testutils"
"github.com/go-jet/jet/v2/internal/utils/ptr"
"github.com/stretchr/testify/require"
"testing"
@ -54,7 +55,7 @@ WHERE people.people_id = ?;
).MODEL(
model.People{
PeopleName: "Dario",
PeopleHeightCm: testutils.Float64Ptr(190),
PeopleHeightCm: ptr.Of(190.0),
},
).RETURNING(
People.AllColumns,

View file

@ -2,6 +2,7 @@ package sqlite
import (
"context"
"github.com/go-jet/jet/v2/internal/utils/ptr"
model2 "github.com/go-jet/jet/v2/tests/.gentestdata/sqlite/chinook/model"
"github.com/go-jet/jet/v2/tests/.gentestdata/sqlite/chinook/table"
"strings"
@ -846,15 +847,15 @@ func TestSimpleView(t *testing.T) {
require.Equal(t, len(dest), 10)
require.Equal(t, dest[2], model.CustomerList{
ID: testutils.Int32Ptr(3),
Name: testutils.StringPtr("LINDA WILLIAMS"),
Address: testutils.StringPtr("692 Joliet Street"),
ZipCode: testutils.StringPtr("83579"),
Phone: testutils.StringPtr(" "),
City: testutils.StringPtr("Athenai"),
Country: testutils.StringPtr("Greece"),
Notes: testutils.StringPtr("active"),
Sid: testutils.Int32Ptr(1),
ID: ptr.Of(int32(3)),
Name: ptr.Of("LINDA WILLIAMS"),
Address: ptr.Of("692 Joliet Street"),
ZipCode: ptr.Of("83579"),
Phone: ptr.Of(" "),
City: ptr.Of("Athenai"),
Country: ptr.Of("Greece"),
Notes: ptr.Of("active"),
Sid: ptr.Of(int32(1)),
})
}