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.3KB

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