(t *testing.T)
| 16 | } |
| 17 | |
| 18 | func 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 | |
| 58 | func TestParseUniqueConstraints(t *testing.T) { |
| 59 | type UserUnique struct { |
nothing calls this directly
no test coverage detected