mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-25 02:42:43 +01:00
ce8de35334
* Add options to git.Clone to make it more capable * Begin the process of removing the local copy and tidy up * Remove Wiki LocalCopy Checkouts * Remove the last LocalRepo helpers * Remove WithTemporaryFile * Enable push-hooks for these routes * Ensure tests cope with hooks Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove Repository.LocalCopyPath() * Move temporary repo to use the standard temporary path * Fix the tests Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove LocalWikiPath * Fix missing remove Signed-off-by: Andrew Thornton <art27@cantab.net> * Use AppURL for Oauth user link (#6894) * Use AppURL for Oauth user link Fix #6843 * Update oauth.go * Update oauth.go * internal/ssh: ignore env command totally (#6825) * ssh: ignore env command totally * Remove commented code Needed fix described in issue #6889 * Escape the commit message on issues update and title in telegram hook (#6901) * update sdk to latest (#6903) * improve description of branch protection (fix #6886) (#6906) The branch protection description text were not quite accurate. * Fix logging documentation (#6904) * ENABLE_MACARON_REDIRECT should be REDIRECT_MACARON_LOG * Allow DISABLE_ROUTER_LOG to be set in the [log] section * [skip ci] Updated translations via Crowdin * Move sdk structs to modules/structs (#6905) * move sdk structs to moduels/structs * fix tests * fix fmt * fix swagger * fix vendor
160 lines
4.5 KiB
Go
160 lines
4.5 KiB
Go
// Copyright 2017 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 models
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"code.gitea.io/gitea/modules/markup"
|
|
|
|
"github.com/Unknwon/com"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestRepo(t *testing.T) {
|
|
repo := &Repository{Name: "testRepo"}
|
|
repo.Owner = &User{Name: "testOwner"}
|
|
|
|
repo.Units = nil
|
|
|
|
metas := repo.ComposeMetas()
|
|
assert.Equal(t, "testRepo", metas["repo"])
|
|
assert.Equal(t, "testOwner", metas["user"])
|
|
|
|
externalTracker := RepoUnit{
|
|
Type: UnitTypeExternalTracker,
|
|
Config: &ExternalTrackerConfig{
|
|
ExternalTrackerFormat: "https://someurl.com/{user}/{repo}/{issue}",
|
|
},
|
|
}
|
|
|
|
testSuccess := func(expectedStyle string) {
|
|
repo.Units = []*RepoUnit{&externalTracker}
|
|
repo.ExternalMetas = nil
|
|
metas := repo.ComposeMetas()
|
|
assert.Equal(t, expectedStyle, metas["style"])
|
|
assert.Equal(t, "testRepo", metas["repo"])
|
|
assert.Equal(t, "testOwner", metas["user"])
|
|
assert.Equal(t, "https://someurl.com/{user}/{repo}/{issue}", metas["format"])
|
|
}
|
|
|
|
testSuccess(markup.IssueNameStyleNumeric)
|
|
|
|
externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markup.IssueNameStyleAlphanumeric
|
|
testSuccess(markup.IssueNameStyleAlphanumeric)
|
|
|
|
externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markup.IssueNameStyleNumeric
|
|
testSuccess(markup.IssueNameStyleNumeric)
|
|
}
|
|
|
|
func TestGetRepositoryCount(t *testing.T) {
|
|
assert.NoError(t, PrepareTestDatabase())
|
|
|
|
count, err1 := GetRepositoryCount(&User{ID: int64(10)})
|
|
privateCount, err2 := GetPrivateRepositoryCount(&User{ID: int64(10)})
|
|
publicCount, err3 := GetPublicRepositoryCount(&User{ID: int64(10)})
|
|
assert.NoError(t, err1)
|
|
assert.NoError(t, err2)
|
|
assert.NoError(t, err3)
|
|
assert.Equal(t, int64(3), count)
|
|
assert.Equal(t, (privateCount + publicCount), count)
|
|
}
|
|
|
|
func TestGetPublicRepositoryCount(t *testing.T) {
|
|
assert.NoError(t, PrepareTestDatabase())
|
|
|
|
count, err := GetPublicRepositoryCount(&User{ID: int64(10)})
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, int64(1), count)
|
|
}
|
|
|
|
func TestGetPrivateRepositoryCount(t *testing.T) {
|
|
assert.NoError(t, PrepareTestDatabase())
|
|
|
|
count, err := GetPrivateRepositoryCount(&User{ID: int64(10)})
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, int64(2), count)
|
|
}
|
|
|
|
func TestUpdateRepositoryVisibilityChanged(t *testing.T) {
|
|
assert.NoError(t, PrepareTestDatabase())
|
|
|
|
// Get sample repo and change visibility
|
|
repo, err := GetRepositoryByID(9)
|
|
repo.IsPrivate = true
|
|
|
|
// Update it
|
|
err = UpdateRepository(repo, true)
|
|
assert.NoError(t, err)
|
|
|
|
// Check visibility of action has become private
|
|
act := Action{}
|
|
_, err = x.ID(3).Get(&act)
|
|
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, true, act.IsPrivate)
|
|
}
|
|
|
|
func TestGetUserFork(t *testing.T) {
|
|
assert.NoError(t, PrepareTestDatabase())
|
|
|
|
// User13 has repo 11 forked from repo10
|
|
repo, err := GetRepositoryByID(10)
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, repo)
|
|
repo, err = repo.GetUserFork(13)
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, repo)
|
|
|
|
repo, err = GetRepositoryByID(9)
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, repo)
|
|
repo, err = repo.GetUserFork(13)
|
|
assert.NoError(t, err)
|
|
assert.Nil(t, repo)
|
|
}
|
|
|
|
func TestForkRepository(t *testing.T) {
|
|
assert.NoError(t, PrepareTestDatabase())
|
|
|
|
// user 13 has already forked repo10
|
|
user := AssertExistsAndLoadBean(t, &User{ID: 13}).(*User)
|
|
repo := AssertExistsAndLoadBean(t, &Repository{ID: 10}).(*Repository)
|
|
|
|
fork, err := ForkRepository(user, user, repo, "test", "test")
|
|
assert.Nil(t, fork)
|
|
assert.Error(t, err)
|
|
assert.True(t, IsErrRepoAlreadyExist(err))
|
|
}
|
|
|
|
func TestRepoAPIURL(t *testing.T) {
|
|
assert.NoError(t, PrepareTestDatabase())
|
|
repo := AssertExistsAndLoadBean(t, &Repository{ID: 10}).(*Repository)
|
|
|
|
assert.Equal(t, "https://try.gitea.io/api/v1/repos/user12/repo10", repo.APIURL())
|
|
}
|
|
|
|
func TestTransferOwnership(t *testing.T) {
|
|
assert.NoError(t, PrepareTestDatabase())
|
|
|
|
doer := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
|
|
repo := AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository)
|
|
repo.Owner = AssertExistsAndLoadBean(t, &User{ID: repo.OwnerID}).(*User)
|
|
assert.NoError(t, TransferOwnership(doer, "user2", repo))
|
|
|
|
transferredRepo := AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository)
|
|
assert.EqualValues(t, 2, transferredRepo.OwnerID)
|
|
|
|
assert.False(t, com.IsExist(RepoPath("user3", "repo3")))
|
|
assert.True(t, com.IsExist(RepoPath("user2", "repo3")))
|
|
AssertExistsAndLoadBean(t, &Action{
|
|
OpType: ActionTransferRepo,
|
|
ActUserID: 2,
|
|
RepoID: 3,
|
|
Content: "user3/repo3",
|
|
})
|
|
|
|
CheckConsistencyFor(t, &Repository{}, &User{}, &Team{})
|
|
}
|