summaryrefslogtreecommitdiffstats
path: root/models/issue_dependency_test.go
diff options
context:
space:
mode:
authorkolaente <konrad@kola-entertainments.de>2018-07-17 23:23:58 +0200
committertechknowlogick <techknowlogick@users.noreply.github.com>2018-07-17 17:23:58 -0400
commit1bff02de55331e11de3627d5c5628feb2cd97387 (patch)
treed6d6ace5f246c1555b294bf096763260f7d74d7b /models/issue_dependency_test.go
parent7be5935c55dcdf198efdf1306bbeb2b54aa0b900 (diff)
downloadgitea-1bff02de55331e11de3627d5c5628feb2cd97387.tar.gz
gitea-1bff02de55331e11de3627d5c5628feb2cd97387.zip
Added dependencies for issues (#2196) (#2531)
Diffstat (limited to 'models/issue_dependency_test.go')
-rw-r--r--models/issue_dependency_test.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/models/issue_dependency_test.go b/models/issue_dependency_test.go
new file mode 100644
index 0000000000..571bce3184
--- /dev/null
+++ b/models/issue_dependency_test.go
@@ -0,0 +1,57 @@
+// 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"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestCreateIssueDependency(t *testing.T) {
+ // Prepare
+ assert.NoError(t, PrepareTestDatabase())
+
+ user1, err := 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 = CreateIssueDependency(user1, issue1, issue2)
+ assert.NoError(t, err)
+
+ // Do it again to see if it will check if the dependency already exists
+ err = CreateIssueDependency(user1, issue1, issue2)
+ assert.Error(t, err)
+ assert.True(t, IsErrDependencyExists(err))
+
+ // Check for circular dependencies
+ err = CreateIssueDependency(user1, issue2, issue1)
+ assert.Error(t, err)
+ assert.True(t, IsErrCircularDependency(err))
+
+ _ = AssertExistsAndLoadBean(t, &Comment{Type: CommentTypeAddDependency, PosterID: user1.ID, IssueID: issue1.ID})
+
+ // Check if dependencies left is correct
+ left, err := IssueNoDependenciesLeft(issue1)
+ assert.NoError(t, err)
+ assert.False(t, left)
+
+ // Close #2 and check again
+ err = issue2.ChangeStatus(user1, issue2.Repo, true)
+ assert.NoError(t, err)
+
+ left, err = IssueNoDependenciesLeft(issue1)
+ assert.NoError(t, err)
+ assert.True(t, left)
+
+ // Test removing the dependency
+ err = RemoveIssueDependency(user1, issue1, issue2, DependencyTypeBlockedBy)
+ assert.NoError(t, err)
+}