Files
forge/services/repository/create_test.go
zeekayandHanzo Dev aa87442fdd Record upstream authorship centrally in NOTICE instead of in every file header
Source files keep their SPDX-License-Identifier and Hanzo copyright line; the
Gitea, Gogs and LFS Test Server copyrights they used to repeat now live once in
NOTICE, alongside LICENSE. The header lint accepts any copyright line above the
SPDX line, so it no longer demands an upstream one.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-10 17:50:35 -07:00

56 lines
1.7 KiB
Go

// Copyright 2026 Hanzo AI, Inc. All rights reserved.
// SPDX-License-Identifier: MIT
package repository
import (
"os"
"testing"
repo_model "github.com/hanzoai/git/models/repo"
"github.com/hanzoai/git/models/unittest"
user_model "github.com/hanzoai/git/models/user"
"github.com/hanzoai/git/modules/util"
"github.com/stretchr/testify/assert"
)
func TestCreateRepositoryDirectly(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
// a successful creating repository
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
createdRepo, err := CreateRepositoryDirectly(t.Context(), user2, user2, CreateRepoOptions{
Name: "created-repo",
}, true)
assert.NoError(t, err)
assert.NotNil(t, createdRepo)
exist, err := util.IsExist(repo_model.RepoPath(user2.Name, createdRepo.Name))
assert.NoError(t, err)
assert.True(t, exist)
unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: user2.Name, Name: createdRepo.Name})
err = DeleteRepositoryDirectly(t.Context(), createdRepo.ID)
assert.NoError(t, err)
// a failed creating because some mock data
// create the repository directory so that the creation will fail after database record created.
assert.NoError(t, os.MkdirAll(repo_model.RepoPath(user2.Name, createdRepo.Name), os.ModePerm))
createdRepo2, err := CreateRepositoryDirectly(t.Context(), user2, user2, CreateRepoOptions{
Name: "created-repo",
}, true)
assert.Nil(t, createdRepo2)
assert.Error(t, err)
// assert the cleanup is successful
unittest.AssertNotExistsBean(t, &repo_model.Repository{OwnerName: user2.Name, Name: createdRepo.Name})
exist, err = util.IsExist(repo_model.RepoPath(user2.Name, createdRepo.Name))
assert.NoError(t, err)
assert.False(t, exist)
}