Merge pull request #404 from safaci2000/feature/testTools
Replacing several test util function with a generic version
This commit is contained in:
commit
31a6b9582a
18 changed files with 161 additions and 214 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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`,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)),
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue