Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

repository_test.go 1.3KB

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