(t *testing.T, data interface{}, name string, result int64, reason string)
| 10 | ) |
| 11 | |
| 12 | func AssertAssociationCount(t *testing.T, data interface{}, name string, result int64, reason string) { |
| 13 | if count := DB.Model(data).Association(name).Count(); count != result { |
| 14 | t.Fatalf("invalid %v count %v, expects: %v got %v", name, reason, result, count) |
| 15 | } |
| 16 | |
| 17 | var newUser User |
| 18 | if user, ok := data.(User); ok { |
| 19 | DB.Find(&newUser, "id = ?", user.ID) |
| 20 | } else if user, ok := data.(*User); ok { |
| 21 | DB.Find(&newUser, "id = ?", user.ID) |
| 22 | } |
| 23 | |
| 24 | if newUser.ID != 0 { |
| 25 | if count := DB.Model(&newUser).Association(name).Count(); count != result { |
| 26 | t.Fatalf("invalid %v count %v, expects: %v got %v", name, reason, result, count) |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | func TestInvalidAssociation(t *testing.T) { |
| 32 | user := *GetUser("invalid", Config{Company: true, Manager: true}) |
no test coverage detected