2019-11-09 05:54:50 +09: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-09-19 20:49:59 +09:00
|
|
|
"code.gitea.io/gitea/models/db"
|
2019-11-09 05:54:50 +09:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
2021-09-19 20:49:59 +09:00
|
|
|
db.MainTest(m, filepath.Join("..", "..", ".."))
|
2019-11-09 05:54:50 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRenameRepoAction(t *testing.T) {
|
2021-09-19 20:49:59 +09:00
|
|
|
assert.NoError(t, db.PrepareTestDatabase())
|
2019-11-09 05:54:50 +09:00
|
|
|
|
2021-09-19 20:49:59 +09:00
|
|
|
user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
|
|
|
|
repo := db.AssertExistsAndLoadBean(t, &models.Repository{OwnerID: user.ID}).(*models.Repository)
|
2019-11-09 05:54:50 +09: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-09-19 20:49:59 +09:00
|
|
|
db.AssertNotExistsBean(t, actionBean)
|
2019-11-09 05:54:50 +09:00
|
|
|
|
|
|
|
NewNotifier().NotifyRenameRepository(user, repo, oldRepoName)
|
|
|
|
|
2021-09-19 20:49:59 +09:00
|
|
|
db.AssertExistsAndLoadBean(t, actionBean)
|
2019-11-09 05:54:50 +09:00
|
|
|
models.CheckConsistencyFor(t, &models.Action{})
|
|
|
|
}
|