From 7310f30f9db333306fae6f68430de229a493b1f2 Mon Sep 17 00:00:00 2001 From: Ting-Lan Wang Date: Tue, 19 Aug 2025 11:35:39 -0400 Subject: [PATCH 01/10] Fix TestUseDBInHooks and TestExceptionsWithInvalidSql --- tests/hooks_test.go | 10 +++++----- tests/main_test.go | 15 +++++++++------ tests/passed-tests.txt | 4 ++-- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/tests/hooks_test.go b/tests/hooks_test.go index 837531b..944d0c1 100644 --- a/tests/hooks_test.go +++ b/tests/hooks_test.go @@ -296,12 +296,12 @@ func TestUseDBInHooks(t *testing.T) { } var result Product2 - if err := DB.First(&result, "name = ?", "Nice").Error; err != nil { + if err := DB.First(&result, "\"name\" = ?", "Nice").Error; err != nil { t.Fatalf("Failed to query product, got error: %v", err) } var resultClone Product2 - if err := DB.First(&resultClone, "name = ?", "Nice_clone").Error; err != nil { + if err := DB.First(&resultClone, "\"name\" = ?", "Nice_clone").Error; err != nil { t.Fatalf("Failed to find cloned product, got error: %v", err) } @@ -311,7 +311,7 @@ func TestUseDBInHooks(t *testing.T) { DB.Model(&result).Update("Price", 500) var result2 Product2 - DB.First(&result2, "name = ?", "Nice") + DB.First(&result2, "\"name\" = ?", "Nice") if result2.Price != 500 { t.Errorf("Failed to update product's price, expects: %v, got %v", 500, result2.Price) @@ -323,13 +323,13 @@ func TestUseDBInHooks(t *testing.T) { } var result3 Product2 - if err := DB.First(&result3, "name = ?", "Nice2").Error; err != nil { + if err := DB.First(&result3, "\"name\" = ?", "Nice2").Error; err != nil { t.Fatalf("Failed to query product, got error: %v", err) } DB.Model(&result3).Update("Price", 800) var result4 Product2 - DB.First(&result4, "name = ?", "Nice2") + DB.First(&result4, "\"name\" = ?", "Nice2") if result4.Price != 600 { t.Errorf("Admin product's price should not be changed, expects: %v, got %v", 600, result4.Price) diff --git a/tests/main_test.go b/tests/main_test.go index bd0cbec..ea7f36b 100644 --- a/tests/main_test.go +++ b/tests/main_test.go @@ -39,10 +39,9 @@ package tests import ( - "fmt" + "strings" "testing" "time" - "strings" . "github.com/oracle-samples/gorm-oracle/tests/utils" ) @@ -54,9 +53,6 @@ func TestExceptionsWithInvalidSql(t *testing.T) { t.Errorf("Should got error with invalid SQL") } - tx := DB.Model(&User{}).Where("name = ?", "sd;;;aa").Pluck("name", &columns) - fmt.Println(tx.Error) - if DB.Model(&User{}).Where("sdsd.zaaa = ?", "sd;;;aa").Pluck("aaa", &columns).Error == nil { t.Errorf("Should got error with invalid SQL") } @@ -65,13 +61,20 @@ func TestExceptionsWithInvalidSql(t *testing.T) { t.Errorf("Should got error with invalid SQL") } + // Create a user + user := *GetUser("user-for-test-exceptions-with-invalid-sql", Config{}) + + if results := DB.Create(&user); results.Error != nil { + t.Errorf("errors happened when create: %v", results.Error) + } + var count1, count2 int64 DB.Model(&User{}).Count(&count1) if count1 <= 0 { t.Errorf("Should find some users") } - if DB.Where("name = ?", "jinzhu; delete * from users").First(&User{}).Error == nil { + if DB.Where("\"name\" = ?", "jinzhu; delete * from users").First(&User{}).Error == nil { t.Errorf("Should got error with invalid SQL") } diff --git a/tests/passed-tests.txt b/tests/passed-tests.txt index f74b330..49460a5 100644 --- a/tests/passed-tests.txt +++ b/tests/passed-tests.txt @@ -128,7 +128,7 @@ TestOpen TestGroupBy TestRunCallbacks TestCallbacksWithErrors -#TestUseDBInHooks +TestUseDBInHooks TestSetColumn TestHooksForSlice TestFailedToSaveAssociationShouldRollback @@ -150,7 +150,7 @@ TestNestedJoins TestJoinsPreload_Issue7013 TestJoinsPreload_Issue7013_RelationEmpty TestJoinsPreload_Issue7013_NoEntries -#TestExceptionsWithInvalidSql +TestExceptionsWithInvalidSql TestSetAndGet TestMigrate TestAutoMigrateInt8PG From c02274d14ddc6e7840c713841178528bc7f754ba Mon Sep 17 00:00:00 2001 From: Ting-Lan Wang Date: Thu, 21 Aug 2025 09:59:37 -0400 Subject: [PATCH 02/10] Remove t.Skip() --- tests/hooks_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/hooks_test.go b/tests/hooks_test.go index 944d0c1..b732a8d 100644 --- a/tests/hooks_test.go +++ b/tests/hooks_test.go @@ -279,7 +279,6 @@ func (s *Product2) BeforeUpdate(tx *gorm.DB) (err error) { } func TestUseDBInHooks(t *testing.T) { - t.Skip() DB.Migrator().DropTable(&Product2{}) DB.AutoMigrate(&Product2{}) From 643b1d087f8cf581d3d2489eae3ec604a5f34d0e Mon Sep 17 00:00:00 2001 From: Ting-Lan Wang Date: Thu, 21 Aug 2025 10:21:56 -0400 Subject: [PATCH 03/10] Remove unused passed-tests.txt --- tests/passed-tests.txt | 411 ----------------------------------------- 1 file changed, 411 deletions(-) delete mode 100644 tests/passed-tests.txt diff --git a/tests/passed-tests.txt b/tests/passed-tests.txt deleted file mode 100644 index 85cef6a..0000000 --- a/tests/passed-tests.txt +++ /dev/null @@ -1,411 +0,0 @@ -TestBelongsToAssociation -TestBelongsToAssociationForSlice -TestBelongsToDefaultValue -TestBelongsToAssociationUnscoped -TestHasManyAssociation -TestSingleTableHasManyAssociation -TestHasManyAssociationForSlice -TestSingleTableHasManyAssociationForSlice -TestPolymorphicHasManyAssociation -TestPolymorphicHasManyAssociationForSlice -TestHasManyAssociationUnscoped -TestHasManyAssociationReplaceWithNonValidValue -TestHasOneAssociation -TestHasOneAssociationWithSelect -TestHasOneAssociationForSlice -TestPolymorphicHasOneAssociation -TestPolymorphicHasOneAssociationForSlice -TestHasOneAssociationReplaceWithNonValidValue -TestMany2ManyAssociation -TestMany2ManyOmitAssociations -TestMany2ManyAssociationForSlice -TestSingleTableMany2ManyAssociation -TestSingleTableMany2ManyAssociationForSlice -TestDuplicateMany2ManyAssociation -TestConcurrentMany2ManyAssociation -TestMany2ManyDuplicateBelongsToAssociation -TestInvalidAssociation -TestAssociationNotNullClear -#TestForeignKeyConstraints -#TestForeignKeyConstraintsBelongsTo -#TestFullSaveAssociations -TestSaveBelongsCircularReference -TestSaveHasManyCircularReference -TestAssociationError -TestAssociationEmptyQueryClause -TestCallbacks -TestPluginCallbacks -TestCallbacksGet -TestCallbacksRemove -TestWithSingleConnection -TestConnectionWithInvalidQuery -TestNestedConnection -TestMultipleSequentialConnections -TestConnectionAfterDBClose -TestConnectionHandlesPanic -TestConcurrentConnections -TestCountWithGroup -TestCount -TestCountOnEmptyTable -TestCountWithHaving -TestCountWithSoftDelete -TestCreate -TestCreateInBatches -TestCreateInBatchesWithDefaultSize -TestCreateFromMap -#TestCreateWithAssociations -TestBulkCreateWithAssociations -TestBulkCreatePtrDataWithAssociations -#TestPolymorphicHasOne -TestCreateEmptyStruct -TestCreateEmptySlice -TestCreateInvalidSlice -TestCreateWithExistingTimestamp -TestCreateWithNowFuncOverride -TestCreateWithNoGORMPrimaryKey -TestSelectWithCreate -TestOmitWithCreate -TestFirstOrCreateNotExistsTable -TestFirstOrCreateWithPrimaryKey -TestCreateFromSubQuery -TestCreateNilPointer -TestFirstOrCreateRowsAffected -TestCreateWithAutoIncrementCompositeKey -TestCreateOnConflictWithDefaultNull -TestCreateFromMapWithoutPK -TestCreateFromMapWithTable -TestCustomizeColumn -TestCustomColumnAndIgnoredFieldClash -TestCustomizeField -TestDefaultValue -TestDelete -TestDeleteWithTable -TestInlineCondDelete -TestBlockGlobalDelete -TestDeleteWithAssociations -TestDeleteAssociationsWithUnscoped -TestDeleteSliceWithAssociations -TestSoftDeleteReturning -TestDeleteReturning -TestDeleteByPrimaryKeyOnly -TestHardDeleteAfterSoftDelete -TestDeleteWithLimitAndOrder -TestRawSQLDeleteWithLimit -TestRawSQLDelete -TestDeleteCustomTableName -TestDeleteWithSQLExecution -TestDeleteWithCompositePrimaryKey -TestDeleteOmitAssociations -TestDeleteWithSelectField -TestUnscopedBatchDelete -TestDeleteByWhereClause -TestDeleteWithOnDeleteCascade -TestUnscopedDeleteByIDs -TestDistinct -TestEmbeddedStruct -TestEmbeddedPointerTypeStruct -TestEmbeddedScanValuer -TestEmbeddedRelations -TestEmbeddedTagSetting -TestZeroValueEmbeddedStruct -TestUpdateEmbeddedFields -TestDialectorWithErrorTranslatorSupport -TestSupportedDialectorWithErrDuplicatedKey -TestSupportedDialectorWithErrForeignKeyViolated -#TestGenericsCreate -TestGenericsCreateInBatches -#TestGenericsExecAndUpdate -TestGenericsRow -TestGenericsDelete -TestGenericsFindInBatches -TestGenericsScopes -#TestGenericsJoins -TestGenericsNestedJoins -#TestGenericsPreloads -#TestGenericsNestedPreloads -TestGenericsDistinct -TestGenericsGroupHaving -TestGenericsSubQuery -TestGenericsUpsert -TestGenericsWithResult -TestGenericsReuse -TestGenericsWithTransaction -TestGenericsToSQL -TestOpen -TestReturningWithNullToZeroValues -TestGroupBy -TestRunCallbacks -TestCallbacksWithErrors -TestUseDBInHooks -TestSetColumn -TestHooksForSlice -TestFailedToSaveAssociationShouldRollback -TestUpdateCallbacks -TestPropagateUnscoped -#TestOverrideJoinTable -TestJoins -TestJoinsForSlice -TestJoinConds -TestJoinOn -TestJoinsWithSelect -TestJoinWithOmit -TestJoinCount -TestJoinWithSoftDeleted -TestInnerJoins -TestJoinWithSameColumnName -TestJoinArgsWithDB -TestNestedJoins -TestJoinsPreload_Issue7013 -TestJoinsPreload_Issue7013_RelationEmpty -TestJoinsPreload_Issue7013_NoEntries -TestExceptionsWithInvalidSql -TestSetAndGet -TestMigrate -TestAutoMigrateInt8PG -TestAutoMigrateSelfReferential -#TestAutoMigrateNullable -TestSmartMigrateColumn -TestMigrateWithColumnComment -TestMigrateWithUniqueIndex -TestMigrateTable -TestMigrateIndexes -TestMigrateColumnOrder -#TestMigrateColumns -#TestMigrateConstraint -TestMigrateIndexesWithDynamicTableName -TestMigrateSerialColumn -TestMigrateWithSpecialName -TestMigrateAutoIncrement -TestPrimarykeyID -TestCurrentTimestamp -TestUniqueColumn -TestDifferentTypeWithoutDeclaredLength -TestMigrateArrayTypeModel -TestMigrateDonotAlterColumn -TestMigrateSameEmbeddedFieldName -#TestMigrateWithDefaultValue -TestMigrateMySQLWithCustomizedTypes -TestMigrateIgnoreRelations -TestMigrateView -TestMigrateExistingBoolColumnPG -#TestMigrateWithUniqueIndexAndUnique -#TestManyToManyWithMultiPrimaryKeys -#TestManyToManyWithCustomizedForeignKeys -#TestManyToManyWithCustomizedForeignKeys2 -#TestCompositePrimaryKeysAssociations -TestNamedArg -TestNamedArgMultipleSameParamRefs -TestNamedArgNullValues -TestNamedArgMixedNamedAndMapParams -TestNamedArgUnusedParameter -TestNamedArgCaseSensitivity -TestNamedArgInClause -TestNamedArgReservedWordParam -TestNamedPolymorphic -TestNonStdPrimaryKeyAndDefaultValues -TestNestedPreload1 -TestNestedPreload2 -TestNestedPreload3 -TestNestedPreload4 -TestNestedPreload5 -TestNestedPreload6 -TestNestedPreload7 -TestNestedPreload8 -TestNestedPreload9 -TestNestedPreload10 -TestNestedPreload11 -TestNestedPreload12 -TestManyToManyPreloadWithMultiPrimaryKeys -TestManyToManyPreloadForNestedPointer -TestNestedManyToManyPreload -TestNestedManyToManyPreload2 -TestNestedManyToManyPreload3 -TestNestedManyToManyPreload3ForStruct -TestNestedManyToManyPreload4 -TestManyToManyPreloadForPointer -TestNilPointerSlice -TestNilPointerSlice2 -TestPrefixedPreloadDuplication -TestPreloadManyToManyCallbacks -TestPreloadWithAssociations -TestNestedPreload -TestNestedPreloadForSlice -#TestPreloadWithConds -TestNestedPreloadWithConds -TestPreloadEmptyData -TestPreloadGoroutine -TestPreloadWithDiffModel -TestNestedPreloadWithUnscoped -TestNestedPreloadWithNestedJoin -TestMergeNestedPreloadWithNestedJoin -TestNestedPreloadWithPointerJoin -TestEmbedPreload -TestPreparedStmt -TestPreparedStmtFromTransaction -TestPreparedStmtLruFromTransaction -TestPreparedStmtDeadlock -TestPreparedStmtInTransaction -TestPreparedStmtClose -TestPreparedStmtConcurrentClose -#TestFind -TestQueryWithAssociation -TestFindInBatches -TestFindInBatchesWithOffsetLimit -TestFindInBatchesWithError -TestFillSmallerStruct -TestFillSmallerStructWithAllFields -TestNot -TestNotWithAllFields -TestOr -TestOrWithAllFields -#TestPluck -TestSelect -TestOmit -TestOmitWithAllFields -TestMapColumns -TestPluckWithSelect -#TestSelectWithVariables -TestSelectWithArrayInput -TestCustomizedTypePrimaryKey -TestStringPrimaryKeyForNumericValueStartingWithZero -TestSearchWithEmptyChain -TestOrder -TestOrderWithAllFields -TestLimit -TestOffset -TestSearchWithMap -TestSearchWithStruct -TestSubQuery -TestSubQueryWithRaw -TestSubQueryWithHaving -TestScanNullValue -TestQueryWithTableAndConditions -TestQueryWithTableAndConditionsAndAllFields -TestQueryScannerWithSingleColumn -TestQueryResetNullValue -TestQueryError -TestQueryScanToArray -TestRownum -TestNullHandling -TestDualTable -TestStringConcatenation -TestRegexpFunctions -TestBindVariables -TestNumberPrecision -TestScan -TestScanRows -TestScanRowsNullValuesScanToFieldDefault -TestScanToEmbedded -#TestScannerValuer -#TestScannerValuerWithFirstOrCreate -#TestInvalidValuer -TestGORMValuer -TestScopes -TestComplexScopes -TestSerializer -TestSerializerZeroValue -TestSerializerAssignFirstOrCreate -TestSoftDelete -TestDeletedAtUnMarshal -TestDeletedAtOneOr -TestSoftDeleteZeroValue -TestSoftDeleteWithWhereClause -TestSoftDeleteTimeFilter -TestSoftDeleteIdempotent -TestSoftDeleteWithClause -TestSoftDeleteWithCompositeKey -TestSoftDeleteWithPreload -TestSoftDeletedRecordReinsert -TestRow -TestRows -TestRaw -TestRowsWithGroup -TestQueryRaw -TestDryRun -TestExplainSQL -TestGroupConditions -TestCombineStringConditions -TestFromWithJoins -TestToSQL -TestTable -TestTableWithAllFields -TestTableWithNamer -TestTransaction -TestCancelTransaction -TestTransactionWithBlock -TestTransactionRaiseErrorOnRollbackAfterCommit -TestTransactionWithSavePoint -TestNestedTransactionWithBlock -#TestDeeplyNestedTransactionWithBlockAndWrappedCallback -TestDisabledNestedTransaction -TestTransactionOnClosedConn -TestTransactionWithHooks -TestTransactionWithDefaultTimeout -TestComplexNestedTransactions -TestTransactionWithRawSQL -TestUpdateBelongsTo -#TestUpdateHasManyAssociations -TestUpdateHasOne -TestUpdateMany2ManyAssociations -TestUpdate -TestUpdates -TestUpdateColumn -TestBlockGlobalUpdate -TestSelectWithUpdate -TestSelectWithUpdateWithMap -TestWithUpdateWithInvalidMap -TestOmitWithUpdate -TestOmitWithUpdateWithMap -TestSelectWithUpdateColumn -TestOmitWithUpdateColumn -TestUpdateColumnsSkipsAssociations -TestUpdatesWithBlankValues -TestUpdatesTableWithIgnoredValues -TestUpdateFromSubQuery -TestIdempotentSave -TestSave -TestSaveWithPrimaryValue -TestUpdateReturning -TestUpdateWithDiffSchema -TestSaveWithHooks -TestUpdateFrom -TestUpdateWithMultipleWhere -TestUpdatePrimaryKeyField -TestUpdatesWithZeroValue -TestUpdateStringFieldToNull -TestUpdateColumnsWithNulls -TestUpdatesWithStructPointer -TestUpdateCustomDataType -TestBatchUpdateSlice -#TestMixedSaveBatch -#TestDistinctComputedColumn -TestDistinctWithVaryingCase -#TestDistinctWithAggregation -TestUpsert -TestUpsertSlice -TestUpsertWithSave -TestFindOrInitialize -TestUpdateWithMissWhere -TestUpsertCompositePK -TestUpsertIgnoreColumn -TestUpsertReturning -TestUpsertNullValues -TestUpsertSliceMixed -TestUpsertWithExpressions -TestUpsertPrimaryKeyNotUpdated -TestUpsertWithNullUnique -TestUpsertLargeBatch -TestUpsertFromSubquery -TestFindOrCreate -BenchmarkCreate -BenchmarkFind -BenchmarkScan -BenchmarkScanSlice -BenchmarkScanSlicePointer -BenchmarkUpdate -BenchmarkDelete -TestRawQueryInjection -TestWhereClauseInjection -TestUpdateInjection -TestFirstOrCreateInjection -TestUserInsertScenarios From eb02e3ed70c6a1021fb9d23806df6c64f02f3526 Mon Sep 17 00:00:00 2001 From: Ting-Lan Wang Date: Thu, 21 Aug 2025 10:22:51 -0400 Subject: [PATCH 04/10] Enable tests that are passed --- tests/create_test.go | 6 ++---- tests/generics_test.go | 1 - tests/joins_test.go | 10 ---------- tests/scan_test.go | 1 - tests/update_test.go | 1 - 5 files changed, 2 insertions(+), 17 deletions(-) diff --git a/tests/create_test.go b/tests/create_test.go index 266bd06..35a8040 100644 --- a/tests/create_test.go +++ b/tests/create_test.go @@ -181,7 +181,6 @@ func TestCreateFromMap(t *testing.T) { } func TestCreateWithAssociations(t *testing.T) { - t.Skip() user := *GetUser("create_with_associations", Config{ Account: true, Pets: 2, @@ -200,7 +199,7 @@ func TestCreateWithAssociations(t *testing.T) { CheckUser(t, user, user) var user2 User - DB.Preload("Account").Preload("Pets").Preload("Toys").Preload("Company").Preload("Manager").Preload("Team").Preload("Languages").Preload("Friends").Find(&user2, "id = ?", user.ID) + DB.Preload("Account").Preload("Pets").Preload("Toys").Preload("Company").Preload("Manager").Preload("Team").Preload("Languages").Preload("Friends").Find(&user2, "\"id\" = ?", user.ID) CheckUser(t, user2, user) } @@ -265,7 +264,6 @@ func TestBulkCreatePtrDataWithAssociations(t *testing.T) { } func TestPolymorphicHasOne(t *testing.T) { - t.Skip() t.Run("Struct", func(t *testing.T) { pet := Pet{ Name: "PolymorphicHasOne", @@ -279,7 +277,7 @@ func TestPolymorphicHasOne(t *testing.T) { CheckPet(t, pet, pet) var pet2 Pet - DB.Preload("Toy").Find(&pet2, "id = ?", pet.ID) + DB.Preload("Toy").Find(&pet2, "\"id\" = ?", pet.ID) CheckPet(t, pet2, pet) }) diff --git a/tests/generics_test.go b/tests/generics_test.go index 3900eff..85d8edc 100644 --- a/tests/generics_test.go +++ b/tests/generics_test.go @@ -56,7 +56,6 @@ import ( ) func TestGenericsCreate(t *testing.T) { - t.Skip() ctx := context.Background() user := User{Name: "TestGenericsCreate", Age: 18} diff --git a/tests/joins_test.go b/tests/joins_test.go index 21922b3..09e81cc 100644 --- a/tests/joins_test.go +++ b/tests/joins_test.go @@ -52,7 +52,6 @@ import ( ) func TestJoins(t *testing.T) { - t.Skip() user := *GetUser("joins-1", Config{Company: true, Manager: true, Account: true, NamedPet: false}) DB.Create(&user) @@ -66,7 +65,6 @@ func TestJoins(t *testing.T) { } func TestJoinsForSlice(t *testing.T) { - t.Skip() users := []User{ *GetUser("slice-joins-1", Config{Company: true, Manager: true, Account: true}), *GetUser("slice-joins-2", Config{Company: true, Manager: true, Account: true}), @@ -101,8 +99,6 @@ func TestJoinsForSlice(t *testing.T) { } func TestJoinConds(t *testing.T) { - t.Skip() - user := *GetUser("joins-conds", Config{Account: true, Pets: 3}) DB.Save(&user) @@ -157,8 +153,6 @@ func TestJoinConds(t *testing.T) { } func TestJoinOn(t *testing.T) { - t.Skip() - user := *GetUser("joins-on", Config{Pets: 2}) DB.Save(&user) @@ -281,8 +275,6 @@ func TestJoinWithSoftDeleted(t *testing.T) { } func TestInnerJoins(t *testing.T) { - t.Skip() - user := *GetUser("inner-joins-1", Config{Company: true, Manager: true, Account: true, NamedPet: false}) DB.Create(&user) @@ -336,8 +328,6 @@ func TestJoinWithSameColumnName(t *testing.T) { } func TestJoinArgsWithDB(t *testing.T) { - t.Skip() - user := *GetUser("joins-args-db", Config{Pets: 2}) DB.Save(&user) diff --git a/tests/scan_test.go b/tests/scan_test.go index 1b16a80..93e158c 100644 --- a/tests/scan_test.go +++ b/tests/scan_test.go @@ -303,7 +303,6 @@ func TestScanRowsNullValuesScanToFieldDefault(t *testing.T) { } func TestScanToEmbedded(t *testing.T) { - t.Skip() person1 := Person{Name: "person 1"} person2 := Person{Name: "person 2"} DB.Save(&person1).Save(&person2) diff --git a/tests/update_test.go b/tests/update_test.go index 6eea71a..d9eb530 100644 --- a/tests/update_test.go +++ b/tests/update_test.go @@ -1029,7 +1029,6 @@ func TestBatchUpdateSlice(t *testing.T) { } } func TestMixedSaveBatch(t *testing.T) { - t.Skip() users := []*User{ GetUser("existing1", Config{}), GetUser("existing2", Config{}), From fb8389285126753712dc9b7452d4c1f16f5ec2ed Mon Sep 17 00:00:00 2001 From: Ting-Lan Wang Date: Thu, 21 Aug 2025 14:24:14 -0400 Subject: [PATCH 05/10] Fix TestUseDBInHooks --- tests/hooks_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/hooks_test.go b/tests/hooks_test.go index b732a8d..1498269 100644 --- a/tests/hooks_test.go +++ b/tests/hooks_test.go @@ -274,7 +274,10 @@ func (s Product2) BeforeCreate(tx *gorm.DB) (err error) { } func (s *Product2) BeforeUpdate(tx *gorm.DB) (err error) { - tx.Statement.Where("\"owner\" != ?", "admin") + // In Oracle DB, when owner is NULL, the condition "owner" != 'admin' will + // always returns false. + // Hence, we use NVL("owner", 'none') to substitute 'none' when owner is NULL. + tx.Statement.Where("NVL(\"owner\", 'none') != ?", "admin") return } From 8dd23fdd7e4cf6d41253eb98eca7381f5272ce75 Mon Sep 17 00:00:00 2001 From: Ting-Lan Wang Date: Thu, 21 Aug 2025 14:29:22 -0400 Subject: [PATCH 06/10] Restore TestGenericsCreate --- tests/generics_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/generics_test.go b/tests/generics_test.go index 85d8edc..3900eff 100644 --- a/tests/generics_test.go +++ b/tests/generics_test.go @@ -56,6 +56,7 @@ import ( ) func TestGenericsCreate(t *testing.T) { + t.Skip() ctx := context.Background() user := User{Name: "TestGenericsCreate", Age: 18} From 481574d6e41023bf73f4bd5736c3e639dab4672e Mon Sep 17 00:00:00 2001 From: Ting-Lan Wang Date: Thu, 21 Aug 2025 14:57:36 -0400 Subject: [PATCH 07/10] Fix TestScanToEmbedded --- tests/scan_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/scan_test.go b/tests/scan_test.go index 93e158c..5aa0dab 100644 --- a/tests/scan_test.go +++ b/tests/scan_test.go @@ -303,6 +303,11 @@ func TestScanRowsNullValuesScanToFieldDefault(t *testing.T) { } func TestScanToEmbedded(t *testing.T) { + DB.Migrator().DropTable(&Person{}, &Address{}, &PersonAddress{}) + if err := DB.AutoMigrate(&Person{}, &Address{}, &PersonAddress{}); err != nil { + t.Fatalf("Failed to migrate, got %v", err) + } + person1 := Person{Name: "person 1"} person2 := Person{Name: "person 2"} DB.Save(&person1).Save(&person2) From 3d35c0482c63b5273b4d487ad6197532f69bb7c7 Mon Sep 17 00:00:00 2001 From: Ting-Lan Wang Date: Thu, 21 Aug 2025 16:18:26 -0400 Subject: [PATCH 08/10] Update run-tests.yaml --- .github/workflows/run-tests.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yaml b/.github/workflows/run-tests.yaml index 0552caf..1d6f4d7 100644 --- a/.github/workflows/run-tests.yaml +++ b/.github/workflows/run-tests.yaml @@ -6,6 +6,7 @@ jobs: run-tests: runs-on: ubuntu-latest env: + DEBUG: "true" GORM_ORACLEDB_USER: ${{ secrets.GORM_ORACLEDB_USER }} GORM_ORACLEDB_PASSWORD: ${{ secrets.GORM_ORACLEDB_PASSWORD }} GORM_ORACLEDB_CONNECTSTRING: ${{ secrets.GORM_ORACLEDB_CONNECTSTRING }} @@ -47,4 +48,4 @@ jobs: cd tests go get -t github.com/oracle-samples/gorm-oracle/tests go get . - go test -failfast \ No newline at end of file + go test -failfast From 29f207d3b10a9f061de50fba3530a9edd34217d6 Mon Sep 17 00:00:00 2001 From: Ting-Lan Wang Date: Tue, 26 Aug 2025 11:53:22 -0400 Subject: [PATCH 09/10] revert changes in run-tests.yaml --- .github/workflows/run-tests.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/run-tests.yaml b/.github/workflows/run-tests.yaml index 1d6f4d7..da491b5 100644 --- a/.github/workflows/run-tests.yaml +++ b/.github/workflows/run-tests.yaml @@ -6,7 +6,6 @@ jobs: run-tests: runs-on: ubuntu-latest env: - DEBUG: "true" GORM_ORACLEDB_USER: ${{ secrets.GORM_ORACLEDB_USER }} GORM_ORACLEDB_PASSWORD: ${{ secrets.GORM_ORACLEDB_PASSWORD }} GORM_ORACLEDB_CONNECTSTRING: ${{ secrets.GORM_ORACLEDB_CONNECTSTRING }} From 17e41a285c13992aca650306ff423794f8a1580d Mon Sep 17 00:00:00 2001 From: Ting-Lan Wang Date: Fri, 29 Aug 2025 17:09:43 -0400 Subject: [PATCH 10/10] Drop PersonAddress in a single line --- tests/scan_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/scan_test.go b/tests/scan_test.go index 5aa0dab..dd88ecf 100644 --- a/tests/scan_test.go +++ b/tests/scan_test.go @@ -303,6 +303,8 @@ func TestScanRowsNullValuesScanToFieldDefault(t *testing.T) { } func TestScanToEmbedded(t *testing.T) { + // TODO: Fix the issue that PersonAddress is skipped when dropping the tables together with Person and Address + DB.Migrator().DropTable(&PersonAddress{}) DB.Migrator().DropTable(&Person{}, &Address{}, &PersonAddress{}) if err := DB.AutoMigrate(&Person{}, &Address{}, &PersonAddress{}); err != nil { t.Fatalf("Failed to migrate, got %v", err)