2018-07-18 02:53:58 +05:30
|
|
|
// 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.
|
|
|
|
|
2022-06-13 15:07:59 +05:30
|
|
|
package issues_test
|
2018-07-18 02:53:58 +05:30
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-05-04 01:16:28 +05:30
|
|
|
"code.gitea.io/gitea/models/db"
|
2022-06-13 15:07:59 +05:30
|
|
|
issues_model "code.gitea.io/gitea/models/issues"
|
2021-11-12 20:06:47 +05:30
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2021-11-24 15:19:20 +05:30
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2021-11-17 18:04:35 +05:30
|
|
|
|
2018-07-18 02:53:58 +05:30
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCreateIssueDependency(t *testing.T) {
|
|
|
|
// Prepare
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2018-07-18 02:53:58 +05:30
|
|
|
|
2021-11-24 15:19:20 +05:30
|
|
|
user1, err := user_model.GetUserByID(1)
|
2018-07-18 02:53:58 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-06-13 15:07:59 +05:30
|
|
|
issue1, err := issues_model.GetIssueByID(db.DefaultContext, 1)
|
2018-07-18 02:53:58 +05:30
|
|
|
assert.NoError(t, err)
|
2018-12-13 21:25:43 +05:30
|
|
|
|
2022-06-13 15:07:59 +05:30
|
|
|
issue2, err := issues_model.GetIssueByID(db.DefaultContext, 2)
|
2018-07-18 02:53:58 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// Create a dependency and check if it was successful
|
2022-06-13 15:07:59 +05:30
|
|
|
err = issues_model.CreateIssueDependency(user1, issue1, issue2)
|
2018-07-18 02:53:58 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// Do it again to see if it will check if the dependency already exists
|
2022-06-13 15:07:59 +05:30
|
|
|
err = issues_model.CreateIssueDependency(user1, issue1, issue2)
|
2018-07-18 02:53:58 +05:30
|
|
|
assert.Error(t, err)
|
2022-06-13 15:07:59 +05:30
|
|
|
assert.True(t, issues_model.IsErrDependencyExists(err))
|
2018-07-18 02:53:58 +05:30
|
|
|
|
|
|
|
// Check for circular dependencies
|
2022-06-13 15:07:59 +05:30
|
|
|
err = issues_model.CreateIssueDependency(user1, issue2, issue1)
|
2018-07-18 02:53:58 +05:30
|
|
|
assert.Error(t, err)
|
2022-06-13 15:07:59 +05:30
|
|
|
assert.True(t, issues_model.IsErrCircularDependency(err))
|
2018-07-18 02:53:58 +05:30
|
|
|
|
2022-06-13 15:07:59 +05:30
|
|
|
_ = unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{Type: issues_model.CommentTypeAddDependency, PosterID: user1.ID, IssueID: issue1.ID})
|
2018-07-18 02:53:58 +05:30
|
|
|
|
|
|
|
// Check if dependencies left is correct
|
2022-06-13 15:07:59 +05:30
|
|
|
left, err := issues_model.IssueNoDependenciesLeft(db.DefaultContext, issue1)
|
2018-07-18 02:53:58 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.False(t, left)
|
|
|
|
|
|
|
|
// Close #2 and check again
|
2022-06-13 15:07:59 +05:30
|
|
|
_, err = issues_model.ChangeIssueStatus(db.DefaultContext, issue2, user1, true)
|
2018-07-18 02:53:58 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-06-13 15:07:59 +05:30
|
|
|
left, err = issues_model.IssueNoDependenciesLeft(db.DefaultContext, issue1)
|
2018-07-18 02:53:58 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, left)
|
|
|
|
|
|
|
|
// Test removing the dependency
|
2022-06-13 15:07:59 +05:30
|
|
|
err = issues_model.RemoveIssueDependency(user1, issue1, issue2, issues_model.DependencyTypeBlockedBy)
|
2018-07-18 02:53:58 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|