From 3f8c00ff4b3fd243ffb07675d29e7724f889b79e Mon Sep 17 00:00:00 2001 From: mytlogos Date: Mon, 11 Nov 2024 19:48:58 +0100 Subject: [PATCH] test panic with json serializer and nil --- db.go | 2 +- go.mod | 46 ++++++++++++++++++++++++++-------------------- main_test.go | 10 ++++++++++ models.go | 6 ++++++ test.sh | 6 ++++-- 5 files changed, 47 insertions(+), 23 deletions(-) diff --git a/db.go b/db.go index ccab03ed..ce6acfad 100644 --- a/db.go +++ b/db.go @@ -83,7 +83,7 @@ func OpenTestConnection() (db *gorm.DB, err error) { func RunMigrations() { var err error - allModels := []interface{}{&User{}, &Account{}, &Pet{}, &Company{}, &Toy{}, &Language{}} + allModels := []interface{}{&User{}, &Account{}, &Pet{}, &Company{}, &Toy{}, &Language{}, &Entity{}} rand.Seed(time.Now().UnixNano()) rand.Shuffle(len(allModels), func(i, j int) { allModels[i], allModels[j] = allModels[j], allModels[i] }) diff --git a/go.mod b/go.mod index 159394d4..b82f044b 100644 --- a/go.mod +++ b/go.mod @@ -1,35 +1,41 @@ module gorm.io/playground -go 1.20 +go 1.22.0 require ( - gorm.io/driver/mysql v1.5.2 - gorm.io/driver/postgres v1.5.2 - gorm.io/driver/sqlite v1.5.3 - gorm.io/driver/sqlserver v1.5.1 - gorm.io/gen v0.3.25 - gorm.io/gorm v1.25.4 + gorm.io/driver/mysql v1.5.7 + gorm.io/driver/postgres v1.5.9 + gorm.io/driver/sqlite v1.5.6 + gorm.io/driver/sqlserver v1.5.4 + gorm.io/gen v0.3.26 + gorm.io/gorm v1.25.12 ) require ( - github.com/go-sql-driver/mysql v1.7.1 // indirect + filippo.io/edwards25519 v1.1.0 // indirect + github.com/go-sql-driver/mysql v1.8.1 // indirect github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect github.com/golang-sql/sqlexp v0.1.0 // indirect + github.com/google/uuid v1.6.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect - github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect - github.com/jackc/pgx/v5 v5.4.3 // indirect + github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect + github.com/jackc/pgx/v5 v5.7.1 // indirect + github.com/jackc/puddle/v2 v2.2.2 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect - github.com/mattn/go-sqlite3 v1.14.17 // indirect - github.com/microsoft/go-mssqldb v1.5.0 // indirect - golang.org/x/crypto v0.14.0 // indirect - golang.org/x/mod v0.14.0 // indirect - golang.org/x/sys v0.14.0 // indirect - golang.org/x/text v0.13.0 // indirect - golang.org/x/tools v0.15.0 // indirect - gorm.io/datatypes v1.1.1-0.20230130040222-c43177d3cf8c // indirect - gorm.io/hints v1.1.0 // indirect - gorm.io/plugin/dbresolver v1.5.0 // indirect + github.com/mattn/go-sqlite3 v1.14.24 // indirect + github.com/microsoft/go-mssqldb v1.7.2 // indirect + golang.org/x/crypto v0.29.0 // indirect + golang.org/x/mod v0.22.0 // indirect + golang.org/x/sync v0.9.0 // indirect + golang.org/x/sys v0.27.0 // indirect + golang.org/x/text v0.20.0 // indirect + golang.org/x/tools v0.27.0 // indirect + gorm.io/datatypes v1.2.4 // indirect + gorm.io/hints v1.1.2 // indirect + gorm.io/plugin/dbresolver v1.5.3 // indirect ) replace gorm.io/gorm => ./gorm + +replace gorm.io/gen => ./gen diff --git a/main_test.go b/main_test.go index 60a388f7..6c534e73 100644 --- a/main_test.go +++ b/main_test.go @@ -6,6 +6,8 @@ import ( // GORM_REPO: https://github.com/go-gorm/gorm.git // GORM_BRANCH: master +// GORM_GEN_REPO: https://github.com/go-gorm/gen.git +// GORM_GEN_BRANCH: master // TEST_DRIVERS: sqlite, mysql, postgres, sqlserver func TestGORM(t *testing.T) { @@ -18,3 +20,11 @@ func TestGORM(t *testing.T) { t.Errorf("Failed, got error: %v", err) } } + +func TestGORM_failure(t *testing.T) { + value := &Entity{Name: "value"} + + DB.Create(value) + + DB.Save(value) +} diff --git a/models.go b/models.go index 692a6842..721bcc1b 100644 --- a/models.go +++ b/models.go @@ -58,3 +58,9 @@ type Language struct { Code string `gorm:"primarykey"` Name string } + +type Entity struct { + gorm.Model + Name string + AdditionalInfo interface{} `gorm:"serializer:json"` +} diff --git a/test.sh b/test.sh index 7df9088e..8713e543 100755 --- a/test.sh +++ b/test.sh @@ -8,20 +8,22 @@ rm -rf gorm fi [ -d gorm ] || (echo "git clone --depth 1 -b $(cat main_test.go | grep GORM_BRANCH | awk '{print $3}') $(cat main_test.go | grep GORM_REPO | awk '{print $3}')"; git clone --depth 1 -b $(cat main_test.go | grep GORM_BRANCH | awk '{print $3}') $(cat main_test.go | grep GORM_REPO | awk '{print $3}')) +[ -d gen ] || (echo "git clone --depth 1 -b $(cat main_test.go | grep GORM_GEN_BRANCH | awk '{print $3}') $(cat main_test.go | grep GORM_GEN_REPO | awk '{print $3}')"; git clone --depth 1 -b $(cat main_test.go | grep GORM_GEN_BRANCH | awk '{print $3}') $(cat main_test.go | grep GORM_GEN_REPO | awk '{print $3}')) +rm -f gen/examples/go.* go get -u -t ./... # SqlServer for Mac M1 if [[ -z $GITHUB_ACTION ]]; then if [[ $(uname -a) == *" arm64" ]]; then - MSSQL_IMAGE=mcr.microsoft.com/azure-sql-edge docker-compose up --detach --quiet-pull || true + MSSQL_IMAGE=mcr.microsoft.com/azure-sql-edge docker compose up --detach --quiet-pull || true echo "starting" go install github.com/microsoft/go-sqlcmd/cmd/sqlcmd@latest || true SQLCMDPASSWORD=LoremIpsum86 sqlcmd -U sa -S localhost:9930 -Q "IF DB_ID('gorm') IS NULL CREATE DATABASE gorm" > /dev/null || true SQLCMDPASSWORD=LoremIpsum86 sqlcmd -U sa -S localhost:9930 -Q "IF SUSER_ID (N'gorm') IS NULL CREATE LOGIN gorm WITH PASSWORD = 'LoremIpsum86';" > /dev/null || true SQLCMDPASSWORD=LoremIpsum86 sqlcmd -U sa -S localhost:9930 -Q "IF USER_ID (N'gorm') IS NULL CREATE USER gorm FROM LOGIN gorm; ALTER SERVER ROLE sysadmin ADD MEMBER [gorm];" > /dev/null || true else - docker-compose up --detach --quiet-pull + docker compose up --detach --quiet-pull echo "starting..." fi fi