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.

repository_test.go 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2022 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package repository
  4. import (
  5. "testing"
  6. "code.gitea.io/gitea/models/db"
  7. repo_model "code.gitea.io/gitea/models/repo"
  8. "code.gitea.io/gitea/models/unit"
  9. "code.gitea.io/gitea/models/unittest"
  10. "github.com/stretchr/testify/assert"
  11. )
  12. func TestLinkedRepository(t *testing.T) {
  13. assert.NoError(t, unittest.PrepareTestDatabase())
  14. testCases := []struct {
  15. name string
  16. attachID int64
  17. expectedRepo *repo_model.Repository
  18. expectedUnitType unit.Type
  19. }{
  20. {"LinkedIssue", 1, &repo_model.Repository{ID: 1}, unit.TypeIssues},
  21. {"LinkedComment", 3, &repo_model.Repository{ID: 1}, unit.TypePullRequests},
  22. {"LinkedRelease", 9, &repo_model.Repository{ID: 1}, unit.TypeReleases},
  23. {"Notlinked", 10, nil, -1},
  24. }
  25. for _, tc := range testCases {
  26. t.Run(tc.name, func(t *testing.T) {
  27. attach, err := repo_model.GetAttachmentByID(db.DefaultContext, tc.attachID)
  28. assert.NoError(t, err)
  29. repo, unitType, err := LinkedRepository(db.DefaultContext, attach)
  30. assert.NoError(t, err)
  31. if tc.expectedRepo != nil {
  32. assert.Equal(t, tc.expectedRepo.ID, repo.ID)
  33. }
  34. assert.Equal(t, tc.expectedUnitType, unitType)
  35. })
  36. }
  37. }