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

Function TestParseCheck

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

Source from the content-addressed store, hash-verified

16}
17
18func TestParseCheck(t *testing.T) {
19 user, err := schema.Parse(&UserCheck{}, &sync.Map{}, schema.NamingStrategy{})
20 if err != nil {
21 t.Fatalf("failed to parse user check, got error %v", err)
22 }
23
24 results := map[string]schema.CheckConstraint{
25 "name_checker": {
26 Name: "name_checker",
27 Constraint: "name <> 'jinzhu'",
28 },
29 "chk_user_checks_name2": {
30 Name: "chk_user_checks_name2",
31 Constraint: "name <> 'jinzhu'",
32 },
33 "chk_user_checks_name3": {
34 Name: "chk_user_checks_name3",
35 Constraint: "name <> 'jinzhu'",
36 },
37 }
38
39 checks := user.ParseCheckConstraints()
40
41 for k, result := range results {
42 v, ok := checks[k]
43 if !ok {
44 t.Errorf("Failed to found check %v from parsed checks %+v", k, checks)
45 }
46
47 for _, name := range []string{"Name", "Constraint"} {
48 if reflect.ValueOf(result).FieldByName(name).Interface() != reflect.ValueOf(v).FieldByName(name).Interface() {
49 t.Errorf(
50 "check %v %v should equal, expects %v, got %v",
51 k, name, reflect.ValueOf(result).FieldByName(name).Interface(), reflect.ValueOf(v).FieldByName(name).Interface(),
52 )
53 }
54 }
55 }
56}
57
58func TestParseUniqueConstraints(t *testing.T) {
59 type UserUnique struct {

Callers

nothing calls this directly

Calls 2

ParseFunction · 0.92
ParseCheckConstraintsMethod · 0.80

Tested by

no test coverage detected