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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package feed
  4. import (
  5. "path/filepath"
  6. "strings"
  7. "testing"
  8. activities_model "code.gitea.io/gitea/models/activities"
  9. "code.gitea.io/gitea/models/db"
  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. _ "code.gitea.io/gitea/models/actions"
  14. "github.com/stretchr/testify/assert"
  15. )
  16. func TestMain(m *testing.M) {
  17. unittest.MainTest(m, &unittest.TestOptions{
  18. GiteaRootPath: filepath.Join("..", ".."),
  19. })
  20. }
  21. func TestRenameRepoAction(t *testing.T) {
  22. assert.NoError(t, unittest.PrepareTestDatabase())
  23. user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
  24. repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerID: user.ID})
  25. repo.Owner = user
  26. oldRepoName := repo.Name
  27. const newRepoName = "newRepoName"
  28. repo.Name = newRepoName
  29. repo.LowerName = strings.ToLower(newRepoName)
  30. actionBean := &activities_model.Action{
  31. OpType: activities_model.ActionRenameRepo,
  32. ActUserID: user.ID,
  33. ActUser: user,
  34. RepoID: repo.ID,
  35. Repo: repo,
  36. IsPrivate: repo.IsPrivate,
  37. Content: oldRepoName,
  38. }
  39. unittest.AssertNotExistsBean(t, actionBean)
  40. NewNotifier().RenameRepository(db.DefaultContext, user, repo, oldRepoName)
  41. unittest.AssertExistsAndLoadBean(t, actionBean)
  42. unittest.CheckConsistencyFor(t, &activities_model.Action{})
  43. }