2019-11-08 21:54:50 +01:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package action
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models"
|
2021-12-10 02:27:50 +01:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-12 15:36:47 +01:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2021-11-24 10:49:20 +01:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2021-11-17 13:34:35 +01:00
|
|
|
|
2019-11-08 21:54:50 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
2022-04-14 15:58:21 +02:00
|
|
|
unittest.MainTest(m, &unittest.TestOptions{
|
|
|
|
GiteaRootPath: filepath.Join("..", "..", ".."),
|
|
|
|
})
|
2019-11-08 21:54:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRenameRepoAction(t *testing.T) {
|
2021-11-12 15:36:47 +01:00
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2019-11-08 21:54:50 +01:00
|
|
|
|
2022-08-16 04:22:25 +02:00
|
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerID: user.ID})
|
2019-11-08 21:54:50 +01:00
|
|
|
repo.Owner = user
|
|
|
|
|
|
|
|
oldRepoName := repo.Name
|
|
|
|
const newRepoName = "newRepoName"
|
|
|
|
repo.Name = newRepoName
|
|
|
|
repo.LowerName = strings.ToLower(newRepoName)
|
|
|
|
|
|
|
|
actionBean := &models.Action{
|
|
|
|
OpType: models.ActionRenameRepo,
|
|
|
|
ActUserID: user.ID,
|
|
|
|
ActUser: user,
|
|
|
|
RepoID: repo.ID,
|
|
|
|
Repo: repo,
|
|
|
|
IsPrivate: repo.IsPrivate,
|
|
|
|
Content: oldRepoName,
|
|
|
|
}
|
2021-11-16 09:53:21 +01:00
|
|
|
unittest.AssertNotExistsBean(t, actionBean)
|
2019-11-08 21:54:50 +01:00
|
|
|
|
|
|
|
NewNotifier().NotifyRenameRepository(user, repo, oldRepoName)
|
|
|
|
|
2021-11-16 09:53:21 +01:00
|
|
|
unittest.AssertExistsAndLoadBean(t, actionBean)
|
|
|
|
unittest.CheckConsistencyFor(t, &models.Action{})
|
2019-11-08 21:54:50 +01:00
|
|
|
}
|