MCPcopy
hub / github.com/go-gorm/gorm / TestMigrateConstraint

Function TestMigrateConstraint

tests/migrate_test.go:804–828  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

802}
803
804func 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
830type DynamicUser struct {
831 gorm.Model

Callers

nothing calls this directly

Calls 4

HasConstraintMethod · 0.65
MigratorMethod · 0.65
CreateConstraintMethod · 0.65
DropConstraintMethod · 0.65

Tested by

no test coverage detected