code.gitea.io/gitea@v1.21.7/services/repository/fork_test.go (about)

     1  // Copyright 2017 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package repository
     5  
     6  import (
     7  	"testing"
     8  
     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/modules/git"
    13  	"code.gitea.io/gitea/modules/setting"
    14  
    15  	"github.com/stretchr/testify/assert"
    16  )
    17  
    18  func TestForkRepository(t *testing.T) {
    19  	assert.NoError(t, unittest.PrepareTestDatabase())
    20  
    21  	// user 13 has already forked repo10
    22  	user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 13})
    23  	repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 10})
    24  
    25  	fork, err := ForkRepository(git.DefaultContext, user, user, ForkRepoOptions{
    26  		BaseRepo:    repo,
    27  		Name:        "test",
    28  		Description: "test",
    29  	})
    30  	assert.Nil(t, fork)
    31  	assert.Error(t, err)
    32  	assert.True(t, IsErrForkAlreadyExist(err))
    33  
    34  	// user not reached maximum limit of repositories
    35  	assert.False(t, repo_model.IsErrReachLimitOfRepo(err))
    36  
    37  	// change AllowForkWithoutMaximumLimit to false for the test
    38  	setting.Repository.AllowForkWithoutMaximumLimit = false
    39  	// user has reached maximum limit of repositories
    40  	user.MaxRepoCreation = 0
    41  	fork2, err := ForkRepository(git.DefaultContext, user, user, ForkRepoOptions{
    42  		BaseRepo:    repo,
    43  		Name:        "test",
    44  		Description: "test",
    45  	})
    46  	assert.Nil(t, fork2)
    47  	assert.True(t, repo_model.IsErrReachLimitOfRepo(err))
    48  }