(t *testing.T)
| 802 | } |
| 803 | |
| 804 | func TestMigrateConstraint(t *testing.T) { |
| 805 | names := []string{"Account", "fk_users_account", "Pets", "fk_users_pets", "Company", "fk_users_company", "Team", "fk_users_team", "Languages", "fk_users_languages"} |
| 806 | |
| 807 | for _, name := range names { |
| 808 | if !DB.Migrator().HasConstraint(&User{}, name) { |
| 809 | DB.Migrator().CreateConstraint(&User{}, name) |
| 810 | } |
| 811 | |
| 812 | if err := DB.Migrator().DropConstraint(&User{}, name); err != nil { |
| 813 | t.Fatalf("failed to drop constraint %v, got error %v", name, err) |
| 814 | } |
| 815 | |
| 816 | if DB.Migrator().HasConstraint(&User{}, name) { |
| 817 | t.Fatalf("constraint %v should been deleted", name) |
| 818 | } |
| 819 | |
| 820 | if err := DB.Migrator().CreateConstraint(&User{}, name); err != nil { |
| 821 | t.Fatalf("failed to create constraint %v, got error %v", name, err) |
| 822 | } |
| 823 | |
| 824 | if !DB.Migrator().HasConstraint(&User{}, name) { |
| 825 | t.Fatalf("failed to found constraint %v", name) |
| 826 | } |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | type DynamicUser struct { |
| 831 | gorm.Model |
nothing calls this directly
no test coverage detected