|
|
|
@ -69,20 +69,43 @@ func TestGetMilestoneByRepoID(t *testing.T) { |
|
|
|
|
|
|
|
|
|
func TestGetMilestonesByRepoID(t *testing.T) { |
|
|
|
|
assert.NoError(t, PrepareTestDatabase()) |
|
|
|
|
test := func(repoID int64) { |
|
|
|
|
test := func(repoID int64, state api.StateType) { |
|
|
|
|
repo := AssertExistsAndLoadBean(t, &Repository{ID: repoID}).(*Repository) |
|
|
|
|
milestones, err := GetMilestonesByRepoID(repo.ID) |
|
|
|
|
milestones, err := GetMilestonesByRepoID(repo.ID, state) |
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
assert.Len(t, milestones, repo.NumMilestones) |
|
|
|
|
|
|
|
|
|
var n int |
|
|
|
|
|
|
|
|
|
switch state { |
|
|
|
|
case api.StateClosed: |
|
|
|
|
n = repo.NumClosedMilestones |
|
|
|
|
|
|
|
|
|
case api.StateAll: |
|
|
|
|
n = repo.NumMilestones |
|
|
|
|
|
|
|
|
|
case api.StateOpen: |
|
|
|
|
fallthrough |
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
n = repo.NumOpenMilestones |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
assert.Len(t, milestones, n) |
|
|
|
|
for _, milestone := range milestones { |
|
|
|
|
assert.EqualValues(t, repoID, milestone.RepoID) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
test(1) |
|
|
|
|
test(2) |
|
|
|
|
test(3) |
|
|
|
|
|
|
|
|
|
milestones, err := GetMilestonesByRepoID(NonexistentID) |
|
|
|
|
test(1, api.StateOpen) |
|
|
|
|
test(1, api.StateAll) |
|
|
|
|
test(1, api.StateClosed) |
|
|
|
|
test(2, api.StateOpen) |
|
|
|
|
test(2, api.StateAll) |
|
|
|
|
test(2, api.StateClosed) |
|
|
|
|
test(3, api.StateOpen) |
|
|
|
|
test(3, api.StateClosed) |
|
|
|
|
test(3, api.StateAll) |
|
|
|
|
|
|
|
|
|
milestones, err := GetMilestonesByRepoID(NonexistentID, api.StateOpen) |
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
assert.Len(t, milestones, 0) |
|
|
|
|
} |
|
|
|
|