(t *testing.T)
| 56 | } |
| 57 | |
| 58 | func TestParseUniqueConstraints(t *testing.T) { |
| 59 | type UserUnique struct { |
| 60 | Name1 string `gorm:"unique"` |
| 61 | Name2 string `gorm:"uniqueIndex"` |
| 62 | } |
| 63 | |
| 64 | user, err := schema.Parse(&UserUnique{}, &sync.Map{}, schema.NamingStrategy{}) |
| 65 | if err != nil { |
| 66 | t.Fatalf("failed to parse user unique, got error %v", err) |
| 67 | } |
| 68 | constraints := user.ParseUniqueConstraints() |
| 69 | |
| 70 | results := map[string]schema.UniqueConstraint{ |
| 71 | "uni_user_uniques_name1": { |
| 72 | Name: "uni_user_uniques_name1", |
| 73 | Field: &schema.Field{Name: "Name1", Unique: true}, |
| 74 | }, |
| 75 | } |
| 76 | for k, result := range results { |
| 77 | v, ok := constraints[k] |
| 78 | if !ok { |
| 79 | t.Errorf("Failed to found unique constraint %v from parsed constraints %+v", k, constraints) |
| 80 | } |
| 81 | tests.AssertObjEqual(t, result, v, "Name") |
| 82 | tests.AssertObjEqual(t, result.Field, v.Field, "Name", "Unique", "UniqueIndex") |
| 83 | } |
| 84 | } |
nothing calls this directly
no test coverage detected