Fork to maintain patches against the official gitea for https://code.ceondo.com https://github.com/go-gitea/gitea

repo_redirect_test.go 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2017 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 TestLookupRepoRedirect(t *testing.T) {
  10. assert.NoError(t, PrepareTestDatabase())
  11. repoID, err := LookupRepoRedirect(2, "oldrepo1")
  12. assert.NoError(t, err)
  13. assert.EqualValues(t, 1, repoID)
  14. _, err = LookupRepoRedirect(NonexistentID, "doesnotexist")
  15. assert.True(t, IsErrRepoRedirectNotExist(err))
  16. }
  17. func TestNewRepoRedirect(t *testing.T) {
  18. // redirect to a completely new name
  19. assert.NoError(t, PrepareTestDatabase())
  20. repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
  21. assert.NoError(t, NewRepoRedirect(repo.OwnerID, repo.ID, repo.Name, "newreponame"))
  22. AssertExistsAndLoadBean(t, &RepoRedirect{
  23. OwnerID: repo.OwnerID,
  24. LowerName: repo.LowerName,
  25. RedirectRepoID: repo.ID,
  26. })
  27. AssertExistsAndLoadBean(t, &RepoRedirect{
  28. OwnerID: repo.OwnerID,
  29. LowerName: "oldrepo1",
  30. RedirectRepoID: repo.ID,
  31. })
  32. }
  33. func TestNewRepoRedirect2(t *testing.T) {
  34. // redirect to previously used name
  35. assert.NoError(t, PrepareTestDatabase())
  36. repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
  37. assert.NoError(t, NewRepoRedirect(repo.OwnerID, repo.ID, repo.Name, "oldrepo1"))
  38. AssertExistsAndLoadBean(t, &RepoRedirect{
  39. OwnerID: repo.OwnerID,
  40. LowerName: repo.LowerName,
  41. RedirectRepoID: repo.ID,
  42. })
  43. AssertNotExistsBean(t, &RepoRedirect{
  44. OwnerID: repo.OwnerID,
  45. LowerName: "oldrepo1",
  46. RedirectRepoID: repo.ID,
  47. })
  48. }
  49. func TestNewRepoRedirect3(t *testing.T) {
  50. // redirect for a previously-unredirected repo
  51. assert.NoError(t, PrepareTestDatabase())
  52. repo := AssertExistsAndLoadBean(t, &Repository{ID: 2}).(*Repository)
  53. assert.NoError(t, NewRepoRedirect(repo.OwnerID, repo.ID, repo.Name, "newreponame"))
  54. AssertExistsAndLoadBean(t, &RepoRedirect{
  55. OwnerID: repo.OwnerID,
  56. LowerName: repo.LowerName,
  57. RedirectRepoID: repo.ID,
  58. })
  59. }