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.
64 lines
2.0 KiB
64 lines
2.0 KiB
7 years ago
|
// 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.
|
||
|
|
||
3 years ago
|
package issues_test
|
||
7 years ago
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
3 years ago
|
"code.gitea.io/gitea/models/db"
|
||
3 years ago
|
issues_model "code.gitea.io/gitea/models/issues"
|
||
3 years ago
|
"code.gitea.io/gitea/models/unittest"
|
||
3 years ago
|
user_model "code.gitea.io/gitea/models/user"
|
||
3 years ago
|
|
||
7 years ago
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func TestCreateIssueDependency(t *testing.T) {
|
||
|
// Prepare
|
||
3 years ago
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||
7 years ago
|
|
||
3 years ago
|
user1, err := user_model.GetUserByID(1)
|
||
7 years ago
|
assert.NoError(t, err)
|
||
|
|
||
3 years ago
|
issue1, err := issues_model.GetIssueByID(db.DefaultContext, 1)
|
||
7 years ago
|
assert.NoError(t, err)
|
||
6 years ago
|
|
||
3 years ago
|
issue2, err := issues_model.GetIssueByID(db.DefaultContext, 2)
|
||
7 years ago
|
assert.NoError(t, err)
|
||
|
|
||
|
// Create a dependency and check if it was successful
|
||
3 years ago
|
err = issues_model.CreateIssueDependency(user1, issue1, issue2)
|
||
7 years ago
|
assert.NoError(t, err)
|
||
|
|
||
|
// Do it again to see if it will check if the dependency already exists
|
||
3 years ago
|
err = issues_model.CreateIssueDependency(user1, issue1, issue2)
|
||
7 years ago
|
assert.Error(t, err)
|
||
3 years ago
|
assert.True(t, issues_model.IsErrDependencyExists(err))
|
||
7 years ago
|
|
||
|
// Check for circular dependencies
|
||
3 years ago
|
err = issues_model.CreateIssueDependency(user1, issue2, issue1)
|
||
7 years ago
|
assert.Error(t, err)
|
||
3 years ago
|
assert.True(t, issues_model.IsErrCircularDependency(err))
|
||
7 years ago
|
|
||
3 years ago
|
_ = unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{Type: issues_model.CommentTypeAddDependency, PosterID: user1.ID, IssueID: issue1.ID})
|
||
7 years ago
|
|
||
|
// Check if dependencies left is correct
|
||
3 years ago
|
left, err := issues_model.IssueNoDependenciesLeft(db.DefaultContext, issue1)
|
||
7 years ago
|
assert.NoError(t, err)
|
||
|
assert.False(t, left)
|
||
|
|
||
|
// Close #2 and check again
|
||
3 years ago
|
_, err = issues_model.ChangeIssueStatus(db.DefaultContext, issue2, user1, true)
|
||
7 years ago
|
assert.NoError(t, err)
|
||
|
|
||
3 years ago
|
left, err = issues_model.IssueNoDependenciesLeft(db.DefaultContext, issue1)
|
||
7 years ago
|
assert.NoError(t, err)
|
||
|
assert.True(t, left)
|
||
|
|
||
|
// Test removing the dependency
|
||
3 years ago
|
err = issues_model.RemoveIssueDependency(user1, issue1, issue2, issues_model.DependencyTypeBlockedBy)
|
||
7 years ago
|
assert.NoError(t, err)
|
||
|
}
|