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.

consistency_test.go 1.0KB

123456789101112131415161718192021222324252627282930313233
  1. // Copyright 2021 Gitea. 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. "code.gitea.io/gitea/models/db"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. func TestDeleteOrphanedObjects(t *testing.T) {
  11. assert.NoError(t, db.PrepareTestDatabase())
  12. countBefore, err := db.GetEngine(db.DefaultContext).Count(&PullRequest{})
  13. assert.NoError(t, err)
  14. _, err = db.GetEngine(db.DefaultContext).Insert(&PullRequest{IssueID: 1000}, &PullRequest{IssueID: 1001}, &PullRequest{IssueID: 1003})
  15. assert.NoError(t, err)
  16. orphaned, err := CountOrphanedObjects("pull_request", "issue", "pull_request.issue_id=issue.id")
  17. assert.NoError(t, err)
  18. assert.EqualValues(t, 3, orphaned)
  19. err = DeleteOrphanedObjects("pull_request", "issue", "pull_request.issue_id=issue.id")
  20. assert.NoError(t, err)
  21. countAfter, err := db.GetEngine(db.DefaultContext).Count(&PullRequest{})
  22. assert.NoError(t, err)
  23. assert.EqualValues(t, countBefore, countAfter)
  24. }