Платформа ЦРНП "Мирокод" для разработки проектов
https://git.mirocod.ru
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.6 KiB
61 lines
1.6 KiB
// Copyright 2018 The Gitea Authors. All rights reserved. |
|
// Use of this source code is governed by a MIT-style |
|
// license that can be found in the LICENSE file. |
|
|
|
package models |
|
|
|
import ( |
|
"testing" |
|
|
|
"code.gitea.io/gitea/models/unittest" |
|
user_model "code.gitea.io/gitea/models/user" |
|
|
|
"github.com/stretchr/testify/assert" |
|
) |
|
|
|
func TestCreateIssueParent(t *testing.T) { |
|
// Prepare |
|
assert.NoError(t, unittest.PrepareTestDatabase()) |
|
|
|
user1, err := user_model.GetUserByID(1) |
|
assert.NoError(t, err) |
|
|
|
issue1, err := GetIssueByID(1) |
|
assert.NoError(t, err) |
|
|
|
issue2, err := GetIssueByID(2) |
|
assert.NoError(t, err) |
|
|
|
// Create a dependency and check if it was successful |
|
err = CreateIssueParent(user1, issue1, issue2) |
|
assert.NoError(t, err) |
|
|
|
// Do it again to see if it will check if the dependency already exists |
|
err = CreateIssueParent(user1, issue1, issue2) |
|
assert.Error(t, err) |
|
assert.True(t, IsErrParentExists(err)) |
|
|
|
// Check for circular dependencies |
|
err = CreateIssueParent(user1, issue2, issue1) |
|
assert.Error(t, err) |
|
assert.True(t, IsErrCircularParent(err)) |
|
|
|
_ = unittest.AssertExistsAndLoadBean(t, &Comment{Type: CommentTypeAddParent, PosterID: user1.ID, IssueID: issue1.ID}) |
|
|
|
// Check if dependencies left is correct |
|
left, err := IssueNoParentsLeft(issue1) |
|
assert.NoError(t, err) |
|
assert.False(t, left) |
|
|
|
// Close #2 and check again |
|
_, err = issue2.ChangeStatus(user1, true) |
|
assert.NoError(t, err) |
|
|
|
left, err = IssueNoParentsLeft(issue1) |
|
assert.NoError(t, err) |
|
assert.True(t, left) |
|
|
|
// Test removing the dependency |
|
err = RemoveIssueParent(user1, issue1, issue2, ParentTypeFather) |
|
assert.NoError(t, err) |
|
}
|
|
|