2021-12-10 06:57:50 +05:30
|
|
|
// 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.
|
|
|
|
|
2022-06-06 13:31:49 +05:30
|
|
|
package repo_test
|
2021-12-10 06:57:50 +05:30
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models/db"
|
2022-06-06 13:31:49 +05:30
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-12-10 06:57:50 +05:30
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2022-05-20 19:38:52 +05:30
|
|
|
"code.gitea.io/gitea/modules/util"
|
2021-12-10 06:57:50 +05:30
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2022-05-20 19:38:52 +05:30
|
|
|
var (
|
2022-06-06 13:31:49 +05:30
|
|
|
countRepospts = repo_model.CountRepositoryOptions{OwnerID: 10}
|
|
|
|
countReposptsPublic = repo_model.CountRepositoryOptions{OwnerID: 10, Private: util.OptionalBoolFalse}
|
|
|
|
countReposptsPrivate = repo_model.CountRepositoryOptions{OwnerID: 10, Private: util.OptionalBoolTrue}
|
2022-05-20 19:38:52 +05:30
|
|
|
)
|
|
|
|
|
2021-12-10 06:57:50 +05:30
|
|
|
func TestGetRepositoryCount(t *testing.T) {
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
|
2022-05-20 19:38:52 +05:30
|
|
|
ctx := db.DefaultContext
|
2022-06-06 13:31:49 +05:30
|
|
|
count, err1 := repo_model.CountRepositories(ctx, countRepospts)
|
|
|
|
privateCount, err2 := repo_model.CountRepositories(ctx, countReposptsPrivate)
|
|
|
|
publicCount, err3 := repo_model.CountRepositories(ctx, countReposptsPublic)
|
2021-12-10 06:57:50 +05:30
|
|
|
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, unittest.PrepareTestDatabase())
|
|
|
|
|
2022-06-06 13:31:49 +05:30
|
|
|
count, err := repo_model.CountRepositories(db.DefaultContext, countReposptsPublic)
|
2021-12-10 06:57:50 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, int64(1), count)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetPrivateRepositoryCount(t *testing.T) {
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
|
2022-06-06 13:31:49 +05:30
|
|
|
count, err := repo_model.CountRepositories(db.DefaultContext, countReposptsPrivate)
|
2021-12-10 06:57:50 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, int64(2), count)
|
|
|
|
}
|
2021-12-12 21:18:20 +05:30
|
|
|
|
|
|
|
func TestRepoAPIURL(t *testing.T) {
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2022-06-06 13:31:49 +05:30
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 10}).(*repo_model.Repository)
|
2021-12-12 21:18:20 +05:30
|
|
|
|
|
|
|
assert.Equal(t, "https://try.gitea.io/api/v1/repos/user12/repo10", repo.APIURL())
|
|
|
|
}
|