From 0abe9d1f27c2a974baaa7ec1756ffa4828ac41dd Mon Sep 17 00:00:00 2001 From: mitika_dodiya Date: Thu, 28 Aug 2025 23:13:31 +0530 Subject: [PATCH] Remove TestManyToManyWithCustomizedForeignKeys Oracle only supports unique constraints matching explicitly defined keys, making this test incompatible. Removing it avoids false failures. --- tests/multi_primary_keys_test.go | 126 ------------------------------- 1 file changed, 126 deletions(-) diff --git a/tests/multi_primary_keys_test.go b/tests/multi_primary_keys_test.go index d36acd9..96d9db3 100644 --- a/tests/multi_primary_keys_test.go +++ b/tests/multi_primary_keys_test.go @@ -172,132 +172,6 @@ func TestManyToManyWithMultiPrimaryKeys(t *testing.T) { } } -func TestManyToManyWithCustomizedForeignKeys(t *testing.T) { - t.Skip() - if name := DB.Dialector.Name(); name == "sqlite" || name == "sqlserver" { - t.Skip("skip sqlite, sqlserver due to it doesn't support multiple primary keys with auto increment") - } - - if name := DB.Dialector.Name(); name == "postgres" { - t.Skip("skip postgres due to it only allow unique constraint matching given keys") - } - - DB.Migrator().DropTable(&Blog{}, &Tag{}, "blog_tags", "locale_blog_tags", "shared_blog_tags") - if err := DB.AutoMigrate(&Blog{}, &Tag{}); err != nil { - t.Fatalf("Failed to auto migrate, got error: %v", err) - } - - blog := Blog{ - Locale: "ZH", - Subject: "subject", - Body: "body", - SharedTags: []Tag{ - {Locale: "ZH", Value: "tag1"}, - {Locale: "ZH", Value: "tag2"}, - }, - } - DB.Save(&blog) - - blog2 := Blog{ - ID: blog.ID, - Locale: "EN", - } - DB.Create(&blog2) - - if !compareTags(blog.SharedTags, []string{"tag1", "tag2"}) { - t.Fatalf("Blog should has two tags") - } - - // Append - tag3 := &Tag{Locale: "ZH", Value: "tag3"} - DB.Model(&blog).Association("SharedTags").Append([]*Tag{tag3}) - if !compareTags(blog.SharedTags, []string{"tag1", "tag2", "tag3"}) { - t.Fatalf("Blog should has three tags after Append") - } - - if DB.Model(&blog).Association("SharedTags").Count() != 3 { - t.Fatalf("Blog should has three tags after Append") - } - - if DB.Model(&blog2).Association("SharedTags").Count() != 3 { - t.Fatalf("Blog should has three tags after Append") - } - - var tags []Tag - DB.Model(&blog).Association("SharedTags").Find(&tags) - if !compareTags(tags, []string{"tag1", "tag2", "tag3"}) { - t.Fatalf("Should find 3 tags") - } - - DB.Model(&blog2).Association("SharedTags").Find(&tags) - if !compareTags(tags, []string{"tag1", "tag2", "tag3"}) { - t.Fatalf("Should find 3 tags") - } - - var blog1 Blog - DB.Preload("SharedTags").Find(&blog1) - if !compareTags(blog1.SharedTags, []string{"tag1", "tag2", "tag3"}) { - t.Fatalf("Preload many2many relations") - } - - tag4 := &Tag{Locale: "ZH", Value: "tag4"} - DB.Model(&blog2).Association("SharedTags").Append(tag4) - - DB.Model(&blog).Association("SharedTags").Find(&tags) - if !compareTags(tags, []string{"tag1", "tag2", "tag3", "tag4"}) { - t.Fatalf("Should find 3 tags") - } - - DB.Model(&blog2).Association("SharedTags").Find(&tags) - if !compareTags(tags, []string{"tag1", "tag2", "tag3", "tag4"}) { - t.Fatalf("Should find 3 tags") - } - - // Replace - tag5 := &Tag{Locale: "ZH", Value: "tag5"} - tag6 := &Tag{Locale: "ZH", Value: "tag6"} - DB.Model(&blog2).Association("SharedTags").Replace(tag5, tag6) - var tags2 []Tag - DB.Model(&blog).Association("SharedTags").Find(&tags2) - if !compareTags(tags2, []string{"tag5", "tag6"}) { - t.Fatalf("Should find 2 tags after Replace") - } - - DB.Model(&blog2).Association("SharedTags").Find(&tags2) - if !compareTags(tags2, []string{"tag5", "tag6"}) { - t.Fatalf("Should find 2 tags after Replace") - } - - if DB.Model(&blog).Association("SharedTags").Count() != 2 { - t.Fatalf("Blog should has three tags after Replace") - } - - // Delete - DB.Model(&blog).Association("SharedTags").Delete(tag5) - var tags3 []Tag - DB.Model(&blog).Association("SharedTags").Find(&tags3) - if !compareTags(tags3, []string{"tag6"}) { - t.Fatalf("Should find 1 tags after Delete") - } - - if DB.Model(&blog).Association("SharedTags").Count() != 1 { - t.Fatalf("Blog should has three tags after Delete") - } - - DB.Model(&blog2).Association("SharedTags").Delete(tag3) - var tags4 []Tag - DB.Model(&blog).Association("SharedTags").Find(&tags4) - if !compareTags(tags4, []string{"tag6"}) { - t.Fatalf("Tag should not be deleted when Delete with a unrelated tag") - } - - // Clear - DB.Model(&blog2).Association("SharedTags").Clear() - if DB.Model(&blog).Association("SharedTags").Count() != 0 { - t.Fatalf("All tags should be cleared") - } -} - func TestManyToManyWithCustomizedForeignKeys2(t *testing.T) { if name := DB.Dialector.Name(); name == "sqlite" || name == "sqlserver" { t.Skip("skip sqlite, sqlserver due to it doesn't support multiple primary keys with auto increment")