Merge pull request #2978 from wy65701436/issue-2975

Issue 2975
This commit is contained in:
Daniel Jiang 2017-08-09 16:05:00 +08:00 committed by GitHub
commit 78bacbc80a
2 changed files with 35 additions and 22 deletions

View File

@ -222,37 +222,40 @@ func TestGetRepositoriesByProject(t *testing.T) {
}
func TestGetAllRepositories(t *testing.T) {
var reposBefore []*models.RepoRecord
reposBefore, err := GetAllRepositories()
if err != nil {
t.Fatalf("error occurred while getting all registories. %v", err)
return
require := require.New(t)
var repos []*models.RepoRecord
repos, err := GetAllRepositories()
require.NoError(err)
allBefore := len(repos)
project1 := models.Project{
OwnerID: 1,
Name: "projectRepo",
Public: 0,
}
allBefore := len(reposBefore)
var err2 error
project1.ProjectID, err2 = AddProject(project1)
require.NoError(err2)
for i := 0; i < 1200; i++ {
end := strconv.Itoa(i)
repoRecord := models.RepoRecord{
Name: "test" + end,
ProjectID: 1,
}
if err := AddRepository(repoRecord); err != nil {
t.Fatalf("Error happens when adding the repository: %v", err)
return
ProjectID: project1.ProjectID,
}
err := AddRepository(repoRecord)
require.NoError(err)
}
var reposAfter []*models.RepoRecord
reposAfter, err2 := GetAllRepositories()
if err2 != nil {
t.Fatalf("error occurred while getting all registories. %v", err2)
return
}
allAfter := len(reposAfter)
repos, err = GetAllRepositories()
require.NoError(err)
allAfter := len(repos)
if allAfter != allBefore+1200 {
t.Errorf("unexpected total: %d != %d", allAfter, allBefore+1200)
}
require.Equal(allAfter, allBefore+1200)
err = clearRepositoryData()
require.NoError(err)
}
func addRepository(repository *models.RepoRecord) error {
@ -262,3 +265,10 @@ func addRepository(repository *models.RepoRecord) error {
func deleteRepository(name string) error {
return DeleteRepository(name)
}
func clearRepositoryData() error {
if err := ClearTable(models.RepoTable); err != nil {
return err
}
return nil
}

View File

@ -18,6 +18,9 @@ import (
"time"
)
//RepoTable is the table name for repository
const RepoTable = "repository"
// RepoRecord holds the record of an repository in DB, all the infors are from the registry notification event.
type RepoRecord struct {
RepositoryID int64 `orm:"pk;auto;column(repository_id)" json:"repository_id"`
@ -32,5 +35,5 @@ type RepoRecord struct {
//TableName is required by by beego orm to map RepoRecord to table repository
func (rp *RepoRecord) TableName() string {
return "repository"
return RepoTable
}