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.

74 lines
2.1 KiB

  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(DefaultDBContext(), 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(DefaultDBContext(), 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(DefaultDBContext(), 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. }