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

Function TestParseUniqueConstraints

schema/constraint_test.go:58–84  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

56}
57
58func 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}

Callers

nothing calls this directly

Calls 3

ParseFunction · 0.92
AssertObjEqualFunction · 0.92

Tested by

no test coverage detected