code.gitea.io/gitea@v1.21.7/models/repo/fork_test.go (about)

     1  // Copyright 2021 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package repo_test
     5  
     6  import (
     7  	"testing"
     8  
     9  	"code.gitea.io/gitea/models/db"
    10  	repo_model "code.gitea.io/gitea/models/repo"
    11  	"code.gitea.io/gitea/models/unittest"
    12  
    13  	"github.com/stretchr/testify/assert"
    14  )
    15  
    16  func TestGetUserFork(t *testing.T) {
    17  	assert.NoError(t, unittest.PrepareTestDatabase())
    18  
    19  	// User13 has repo 11 forked from repo10
    20  	repo, err := repo_model.GetRepositoryByID(db.DefaultContext, 10)
    21  	assert.NoError(t, err)
    22  	assert.NotNil(t, repo)
    23  	repo, err = repo_model.GetUserFork(db.DefaultContext, repo.ID, 13)
    24  	assert.NoError(t, err)
    25  	assert.NotNil(t, repo)
    26  
    27  	repo, err = repo_model.GetRepositoryByID(db.DefaultContext, 9)
    28  	assert.NoError(t, err)
    29  	assert.NotNil(t, repo)
    30  	repo, err = repo_model.GetUserFork(db.DefaultContext, repo.ID, 13)
    31  	assert.NoError(t, err)
    32  	assert.Nil(t, repo)
    33  }