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