(t *testing.T)
| 172 | } |
| 173 | |
| 174 | func TestParseIndexWithUniqueIndexAndUnique(t *testing.T) { |
| 175 | type IndexTest struct { |
| 176 | FieldA string `gorm:"unique;index"` // unique and index |
| 177 | FieldB string `gorm:"unique"` // unique |
| 178 | |
| 179 | FieldC string `gorm:"index:,unique"` // uniqueIndex |
| 180 | FieldD string `gorm:"uniqueIndex;index"` // uniqueIndex and index |
| 181 | |
| 182 | FieldE1 string `gorm:"uniqueIndex:uniq_field_e1_e2"` // mul uniqueIndex |
| 183 | FieldE2 string `gorm:"uniqueIndex:uniq_field_e1_e2"` |
| 184 | |
| 185 | FieldF1 string `gorm:"uniqueIndex:uniq_field_f1_f2;index"` // mul uniqueIndex and index |
| 186 | FieldF2 string `gorm:"uniqueIndex:uniq_field_f1_f2;"` |
| 187 | |
| 188 | FieldG string `gorm:"unique;uniqueIndex"` // unique and uniqueIndex |
| 189 | |
| 190 | FieldH1 string `gorm:"unique;uniqueIndex:uniq_field_h1_h2"` // unique and mul uniqueIndex |
| 191 | FieldH2 string `gorm:"uniqueIndex:uniq_field_h1_h2"` // unique and mul uniqueIndex |
| 192 | } |
| 193 | indexSchema, err := schema.Parse(&IndexTest{}, &sync.Map{}, schema.NamingStrategy{}) |
| 194 | if err != nil { |
| 195 | t.Fatalf("failed to parse user index, got error %v", err) |
| 196 | } |
| 197 | indices := indexSchema.ParseIndexes() |
| 198 | expectedIndices := []*schema.Index{ |
| 199 | { |
| 200 | Name: "idx_index_tests_field_a", |
| 201 | Fields: []schema.IndexOption{{Field: &schema.Field{Name: "FieldA", Unique: true}}}, |
| 202 | }, |
| 203 | { |
| 204 | Name: "idx_index_tests_field_c", |
| 205 | Class: "UNIQUE", |
| 206 | Fields: []schema.IndexOption{{Field: &schema.Field{Name: "FieldC", UniqueIndex: "idx_index_tests_field_c"}}}, |
| 207 | }, |
| 208 | { |
| 209 | Name: "idx_index_tests_field_d", |
| 210 | Class: "UNIQUE", |
| 211 | Fields: []schema.IndexOption{ |
| 212 | {Field: &schema.Field{Name: "FieldD"}}, |
| 213 | // Note: Duplicate Columns |
| 214 | {Field: &schema.Field{Name: "FieldD"}}, |
| 215 | }, |
| 216 | }, |
| 217 | { |
| 218 | Name: "uniq_field_e1_e2", |
| 219 | Class: "UNIQUE", |
| 220 | Fields: []schema.IndexOption{ |
| 221 | {Field: &schema.Field{Name: "FieldE1"}}, |
| 222 | {Field: &schema.Field{Name: "FieldE2"}}, |
| 223 | }, |
| 224 | }, |
| 225 | { |
| 226 | Name: "uniq_field_f1_f2", |
| 227 | Class: "UNIQUE", |
| 228 | Fields: []schema.IndexOption{ |
| 229 | {Field: &schema.Field{Name: "FieldF1"}}, |
| 230 | {Field: &schema.Field{Name: "FieldF2"}}, |
| 231 | }, |
nothing calls this directly
no test coverage detected