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.

action_test.go 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2019 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 action
  5. import (
  6. "path/filepath"
  7. "strings"
  8. "testing"
  9. "code.gitea.io/gitea/models"
  10. repo_model "code.gitea.io/gitea/models/repo"
  11. "code.gitea.io/gitea/models/unittest"
  12. user_model "code.gitea.io/gitea/models/user"
  13. "github.com/stretchr/testify/assert"
  14. )
  15. func TestMain(m *testing.M) {
  16. unittest.MainTest(m, &unittest.TestOptions{
  17. GiteaRootPath: filepath.Join("..", "..", ".."),
  18. })
  19. }
  20. func TestRenameRepoAction(t *testing.T) {
  21. assert.NoError(t, unittest.PrepareTestDatabase())
  22. user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
  23. repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerID: user.ID}).(*repo_model.Repository)
  24. repo.Owner = user
  25. oldRepoName := repo.Name
  26. const newRepoName = "newRepoName"
  27. repo.Name = newRepoName
  28. repo.LowerName = strings.ToLower(newRepoName)
  29. actionBean := &models.Action{
  30. OpType: models.ActionRenameRepo,
  31. ActUserID: user.ID,
  32. ActUser: user,
  33. RepoID: repo.ID,
  34. Repo: repo,
  35. IsPrivate: repo.IsPrivate,
  36. Content: oldRepoName,
  37. }
  38. unittest.AssertNotExistsBean(t, actionBean)
  39. NewNotifier().NotifyRenameRepository(user, repo, oldRepoName)
  40. unittest.AssertExistsAndLoadBean(t, actionBean)
  41. unittest.CheckConsistencyFor(t, &models.Action{})
  42. }