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