create tests for self-ref has one migration
This commit is contained in:
		
							parent
							
								
									4c8810a848
								
							
						
					
					
						commit
						8efabf38d1
					
				@ -93,6 +93,21 @@ func TestBelongsToWithOnlyReferences2(t *testing.T) {
 | 
				
			|||||||
	})
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestSelfReferentialBelongsTo(t *testing.T) {
 | 
				
			||||||
 | 
						type User struct {
 | 
				
			||||||
 | 
							ID        int32 `gorm:"primaryKey"`
 | 
				
			||||||
 | 
							Name      string
 | 
				
			||||||
 | 
							CreatorID *int32
 | 
				
			||||||
 | 
							Creator   *User
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						checkStructRelation(t, &User{}, Relation{
 | 
				
			||||||
 | 
							Name: "Creator", Type: schema.BelongsTo, Schema: "User", FieldSchema: "User",
 | 
				
			||||||
 | 
							References: []Reference{{"ID", "User", "CreatorID", "User", "", false}},
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestSelfReferentialBelongsToOverrideReferences(t *testing.T) {
 | 
					func TestSelfReferentialBelongsToOverrideReferences(t *testing.T) {
 | 
				
			||||||
	type User struct {
 | 
						type User struct {
 | 
				
			||||||
		ID        int32 `gorm:"primaryKey"`
 | 
							ID        int32 `gorm:"primaryKey"`
 | 
				
			||||||
 | 
				
			|||||||
@ -54,6 +54,27 @@ func TestMigrate(t *testing.T) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestAutoMigrateSelfReferential(t *testing.T) {
 | 
				
			||||||
 | 
						type MigratePerson struct {
 | 
				
			||||||
 | 
							ID        uint
 | 
				
			||||||
 | 
							Name      string
 | 
				
			||||||
 | 
							ManagerID *uint
 | 
				
			||||||
 | 
							Manager   *MigratePerson
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := DB.Debug().Migrator().DropTable(&MigratePerson{}); err != nil {
 | 
				
			||||||
 | 
							t.Fatalf("Failed to drop table, got error %v", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := DB.AutoMigrate(&MigratePerson{}); err != nil {
 | 
				
			||||||
 | 
							t.Fatalf("Failed to auto migrate, but got error %v", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !DB.Migrator().HasConstraint("migrate_people", "fk_migrate_people_manager") {
 | 
				
			||||||
 | 
							t.Fatalf("Failed to find has one constraint between people and managers")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestSmartMigrateColumn(t *testing.T) {
 | 
					func TestSmartMigrateColumn(t *testing.T) {
 | 
				
			||||||
	fullSupported := map[string]bool{"mysql": true, "postgres": true}[DB.Dialector.Name()]
 | 
						fullSupported := map[string]bool{"mysql": true, "postgres": true}[DB.Dialector.Name()]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user