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.

58 lines
1.5 KiB

  1. // Copyright 2018 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestCreateIssueDependency(t *testing.T) {
  10. // Prepare
  11. assert.NoError(t, PrepareTestDatabase())
  12. user1, err := GetUserByID(1)
  13. assert.NoError(t, err)
  14. issue1, err := GetIssueByID(1)
  15. assert.NoError(t, err)
  16. issue2, err := GetIssueByID(2)
  17. assert.NoError(t, err)
  18. // Create a dependency and check if it was successful
  19. err = CreateIssueDependency(user1, issue1, issue2)
  20. assert.NoError(t, err)
  21. // Do it again to see if it will check if the dependency already exists
  22. err = CreateIssueDependency(user1, issue1, issue2)
  23. assert.Error(t, err)
  24. assert.True(t, IsErrDependencyExists(err))
  25. // Check for circular dependencies
  26. err = CreateIssueDependency(user1, issue2, issue1)
  27. assert.Error(t, err)
  28. assert.True(t, IsErrCircularDependency(err))
  29. _ = AssertExistsAndLoadBean(t, &Comment{Type: CommentTypeAddDependency, PosterID: user1.ID, IssueID: issue1.ID})
  30. // Check if dependencies left is correct
  31. left, err := IssueNoDependenciesLeft(issue1)
  32. assert.NoError(t, err)
  33. assert.False(t, left)
  34. // Close #2 and check again
  35. _, err = issue2.ChangeStatus(user1, true)
  36. assert.NoError(t, err)
  37. left, err = IssueNoDependenciesLeft(issue1)
  38. assert.NoError(t, err)
  39. assert.True(t, left)
  40. // Test removing the dependency
  41. err = RemoveIssueDependency(user1, issue1, issue2, DependencyTypeBlockedBy)
  42. assert.NoError(t, err)
  43. }