mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-24 16:16:35 -05:00
5723240490
* some repository refactors * remove unnecessary code * Fix test * Remove unnecessary banner
51 lines
1.5 KiB
Go
51 lines
1.5 KiB
Go
// 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"
|
|
user_model "code.gitea.io/gitea/models/user"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGetRepositoryCount(t *testing.T) {
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
count, err1 := GetRepositoryCount(db.DefaultContext, 10)
|
|
privateCount, err2 := GetPrivateRepositoryCount(&user_model.User{ID: int64(10)})
|
|
publicCount, err3 := GetPublicRepositoryCount(&user_model.User{ID: int64(10)})
|
|
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())
|
|
|
|
count, err := GetPublicRepositoryCount(&user_model.User{ID: int64(10)})
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, int64(1), count)
|
|
}
|
|
|
|
func TestGetPrivateRepositoryCount(t *testing.T) {
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
count, err := GetPrivateRepositoryCount(&user_model.User{ID: int64(10)})
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, int64(2), count)
|
|
}
|
|
|
|
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())
|
|
}
|