Fix consistency check (#866)
This commit is contained in:
parent
d2329e1c26
commit
181c8d9c99
4 changed files with 27 additions and 10 deletions
|
@ -73,37 +73,46 @@ func (user *User) CheckForConsistency(t *testing.T) {
|
|||
assertCount(t, &Team{OrgID: user.ID}, user.NumTeams)
|
||||
assertCount(t, &Follow{UserID: user.ID}, user.NumFollowing)
|
||||
assertCount(t, &Follow{FollowID: user.ID}, user.NumFollowers)
|
||||
if user.Type != UserTypeOrganization {
|
||||
assert.EqualValues(t, 0, user.NumMembers)
|
||||
assert.EqualValues(t, 0, user.NumTeams)
|
||||
}
|
||||
}
|
||||
|
||||
func (repo *Repository) CheckForConsistency(t *testing.T) {
|
||||
assertCount(t, &Star{RepoID: repo.ID}, repo.NumStars)
|
||||
assertCount(t, &Watch{RepoID: repo.ID}, repo.NumWatches)
|
||||
assertCount(t, &Issue{RepoID: repo.ID}, repo.NumIssues)
|
||||
assertCount(t, &Milestone{RepoID: repo.ID}, repo.NumMilestones)
|
||||
assertCount(t, &Repository{ForkID: repo.ID}, repo.NumForks)
|
||||
if repo.IsFork {
|
||||
AssertExistsAndLoadBean(t, &Repository{ID: repo.ForkID})
|
||||
}
|
||||
|
||||
actual := getCount(t, x.Where("is_closed=1"), &Issue{RepoID: repo.ID})
|
||||
actual := getCount(t, x.Where("is_pull=?", false), &Issue{RepoID: repo.ID})
|
||||
assert.EqualValues(t, repo.NumIssues, actual,
|
||||
"Unexpected number of issues for repo %+v", repo)
|
||||
|
||||
actual = getCount(t, x.Where("is_pull=? AND is_closed=?", false, true), &Issue{RepoID: repo.ID})
|
||||
assert.EqualValues(t, repo.NumClosedIssues, actual,
|
||||
"Unexpected number of closed issues for repo %+v", repo)
|
||||
|
||||
actual = getCount(t, x.Where("is_pull=1"), &Issue{RepoID: repo.ID})
|
||||
actual = getCount(t, x.Where("is_pull=?", true), &Issue{RepoID: repo.ID})
|
||||
assert.EqualValues(t, repo.NumPulls, actual,
|
||||
"Unexpected number of pulls for repo %+v", repo)
|
||||
|
||||
actual = getCount(t, x.Where("is_pull=1 AND is_closed=1"), &Issue{RepoID: repo.ID})
|
||||
actual = getCount(t, x.Where("is_pull=? AND is_closed=?", true, true), &Issue{RepoID: repo.ID})
|
||||
assert.EqualValues(t, repo.NumClosedPulls, actual,
|
||||
"Unexpected number of closed pulls for repo %+v", repo)
|
||||
|
||||
actual = getCount(t, x.Where("is_closed=1"), &Milestone{RepoID: repo.ID})
|
||||
actual = getCount(t, x.Where("is_closed=?", true), &Milestone{RepoID: repo.ID})
|
||||
assert.EqualValues(t, repo.NumClosedMilestones, actual,
|
||||
"Unexpected number of closed milestones for repo %+v", repo)
|
||||
}
|
||||
|
||||
func (issue *Issue) CheckForConsistency(t *testing.T) {
|
||||
assertCount(t, &Comment{IssueID: issue.ID}, issue.NumComments)
|
||||
actual := getCount(t, x.Where("type=?", CommentTypeComment), &Comment{IssueID: issue.ID})
|
||||
assert.EqualValues(t, issue.NumComments, actual,
|
||||
"Unexpected number of comments for issue %+v", issue)
|
||||
if issue.IsPull {
|
||||
pr := AssertExistsAndLoadBean(t, &PullRequest{IssueID: issue.ID}).(*PullRequest)
|
||||
assert.EqualValues(t, pr.Index, issue.Index)
|
||||
|
@ -119,7 +128,7 @@ func (pr *PullRequest) CheckForConsistency(t *testing.T) {
|
|||
func (milestone *Milestone) CheckForConsistency(t *testing.T) {
|
||||
assertCount(t, &Issue{MilestoneID: milestone.ID}, milestone.NumIssues)
|
||||
|
||||
actual := getCount(t, x.Where("is_closed=1"), &Issue{MilestoneID: milestone.ID})
|
||||
actual := getCount(t, x.Where("is_closed=?", true), &Issue{MilestoneID: milestone.ID})
|
||||
assert.EqualValues(t, milestone.NumClosedIssues, actual,
|
||||
"Unexpected number of closed issues for milestone %+v", milestone)
|
||||
}
|
||||
|
@ -137,7 +146,7 @@ func (label *Label) CheckForConsistency(t *testing.T) {
|
|||
|
||||
expected := int64(0)
|
||||
if len(issueIDs) > 0 {
|
||||
expected = getCount(t, x.In("id", issueIDs).Where("is_closed=1"), &Issue{})
|
||||
expected = getCount(t, x.In("id", issueIDs).Where("is_closed=?", true), &Issue{})
|
||||
}
|
||||
assert.EqualValues(t, expected, label.NumClosedIssues,
|
||||
"Unexpected number of closed issues for label %+v", label)
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
content: content1
|
||||
is_closed: false
|
||||
is_pull: false
|
||||
num_comments: 1
|
||||
num_comments: 0
|
||||
created_unix: 946684800
|
||||
updated_unix: 978307200
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
lower_name: repo1
|
||||
name: repo1
|
||||
is_private: false
|
||||
num_issues: 4
|
||||
num_issues: 2
|
||||
num_closed_issues: 1
|
||||
num_pulls: 2
|
||||
num_closed_pulls: 0
|
||||
|
|
|
@ -54,6 +54,7 @@ func TestNewLabels(t *testing.T) {
|
|||
for _, label := range labels {
|
||||
AssertExistsAndLoadBean(t, label)
|
||||
}
|
||||
CheckConsistencyFor(t, &Label{}, &Repository{})
|
||||
}
|
||||
|
||||
func TestGetLabelByID(t *testing.T) {
|
||||
|
@ -138,6 +139,7 @@ func TestUpdateLabel(t *testing.T) {
|
|||
assert.NoError(t, UpdateLabel(label))
|
||||
newLabel := AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
|
||||
assert.Equal(t, *label, *newLabel)
|
||||
CheckConsistencyFor(t, &Label{}, &Repository{})
|
||||
}
|
||||
|
||||
func TestDeleteLabel(t *testing.T) {
|
||||
|
@ -150,6 +152,7 @@ func TestDeleteLabel(t *testing.T) {
|
|||
AssertNotExistsBean(t, &Label{ID: label.ID, RepoID: label.RepoID})
|
||||
|
||||
assert.NoError(t, DeleteLabel(NonexistentID, NonexistentID))
|
||||
CheckConsistencyFor(t, &Label{}, &Repository{})
|
||||
}
|
||||
|
||||
func TestHasIssueLabel(t *testing.T) {
|
||||
|
@ -180,6 +183,7 @@ func TestNewIssueLabel(t *testing.T) {
|
|||
|
||||
// re-add existing IssueLabel
|
||||
assert.NoError(t, NewIssueLabel(issue, label, doer))
|
||||
CheckConsistencyFor(t, &Issue{}, &Label{})
|
||||
}
|
||||
|
||||
func TestNewIssueLabels(t *testing.T) {
|
||||
|
@ -208,6 +212,8 @@ func TestNewIssueLabels(t *testing.T) {
|
|||
|
||||
// corner case: test empty slice
|
||||
assert.NoError(t, NewIssueLabels(issue, []*Label{}, doer))
|
||||
|
||||
CheckConsistencyFor(t, &Issue{}, &Label{})
|
||||
}
|
||||
|
||||
func TestDeleteIssueLabel(t *testing.T) {
|
||||
|
@ -241,4 +247,6 @@ func TestDeleteIssueLabel(t *testing.T) {
|
|||
testSuccess(1, 1, 2)
|
||||
testSuccess(2, 5, 2)
|
||||
testSuccess(1, 1, 2) // delete non-existent IssueLabel
|
||||
|
||||
CheckConsistencyFor(t, &Issue{}, &Label{})
|
||||
}
|
||||
|
|
Reference in a new issue