You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
116 lines
3.2 KiB
116 lines
3.2 KiB
6 years ago
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||
|
// Copyright 2018 Jonas Franz. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
|
package migrations
|
||
|
|
||
|
import (
|
||
4 years ago
|
"context"
|
||
6 years ago
|
"testing"
|
||
|
"time"
|
||
|
|
||
|
"code.gitea.io/gitea/models"
|
||
3 years ago
|
"code.gitea.io/gitea/models/db"
|
||
3 years ago
|
"code.gitea.io/gitea/models/unittest"
|
||
5 years ago
|
"code.gitea.io/gitea/modules/graceful"
|
||
3 years ago
|
base "code.gitea.io/gitea/modules/migration"
|
||
5 years ago
|
"code.gitea.io/gitea/modules/structs"
|
||
6 years ago
|
"code.gitea.io/gitea/modules/util"
|
||
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func TestGiteaUploadRepo(t *testing.T) {
|
||
|
// FIXME: Since no accesskey or user/password will trigger rate limit of github, just skip
|
||
|
t.Skip()
|
||
|
|
||
3 years ago
|
unittest.PrepareTestEnv(t)
|
||
6 years ago
|
|
||
3 years ago
|
user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
|
||
6 years ago
|
|
||
|
var (
|
||
4 years ago
|
downloader = NewGithubDownloaderV3(context.Background(), "https://github.com", "", "", "", "go-xorm", "builder")
|
||
6 years ago
|
repoName = "builder-" + time.Now().Format("2006-01-02-15-04-05")
|
||
5 years ago
|
uploader = NewGiteaLocalUploader(graceful.GetManager().HammerContext(), user, user.Name, repoName)
|
||
6 years ago
|
)
|
||
|
|
||
4 years ago
|
err := migrateRepository(downloader, uploader, base.MigrateOptions{
|
||
5 years ago
|
CloneAddr: "https://github.com/go-xorm/builder",
|
||
|
RepoName: repoName,
|
||
6 years ago
|
AuthUsername: "",
|
||
|
|
||
6 years ago
|
Wiki: true,
|
||
|
Issues: true,
|
||
|
Milestones: true,
|
||
|
Labels: true,
|
||
|
Releases: true,
|
||
|
Comments: true,
|
||
|
PullRequests: true,
|
||
|
Private: true,
|
||
|
Mirror: false,
|
||
4 years ago
|
}, nil)
|
||
6 years ago
|
assert.NoError(t, err)
|
||
|
|
||
3 years ago
|
repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{OwnerID: user.ID, Name: repoName}).(*models.Repository)
|
||
6 years ago
|
assert.True(t, repo.HasWiki())
|
||
4 years ago
|
assert.EqualValues(t, models.RepositoryReady, repo.Status)
|
||
6 years ago
|
|
||
3 years ago
|
milestones, _, err := models.GetMilestones(models.GetMilestonesOption{
|
||
4 years ago
|
RepoID: repo.ID,
|
||
|
State: structs.StateOpen,
|
||
|
})
|
||
6 years ago
|
assert.NoError(t, err)
|
||
4 years ago
|
assert.Len(t, milestones, 1)
|
||
6 years ago
|
|
||
3 years ago
|
milestones, _, err = models.GetMilestones(models.GetMilestonesOption{
|
||
4 years ago
|
RepoID: repo.ID,
|
||
|
State: structs.StateClosed,
|
||
|
})
|
||
6 years ago
|
assert.NoError(t, err)
|
||
4 years ago
|
assert.Empty(t, milestones)
|
||
6 years ago
|
|
||
3 years ago
|
labels, err := models.GetLabelsByRepoID(repo.ID, "", db.ListOptions{})
|
||
6 years ago
|
assert.NoError(t, err)
|
||
3 years ago
|
assert.Len(t, labels, 12)
|
||
6 years ago
|
|
||
|
releases, err := models.GetReleasesByRepoID(repo.ID, models.FindReleasesOptions{
|
||
3 years ago
|
ListOptions: db.ListOptions{
|
||
5 years ago
|
PageSize: 10,
|
||
|
Page: 0,
|
||
|
},
|
||
6 years ago
|
IncludeTags: true,
|
||
5 years ago
|
})
|
||
6 years ago
|
assert.NoError(t, err)
|
||
4 years ago
|
assert.Len(t, releases, 8)
|
||
6 years ago
|
|
||
|
releases, err = models.GetReleasesByRepoID(repo.ID, models.FindReleasesOptions{
|
||
3 years ago
|
ListOptions: db.ListOptions{
|
||
5 years ago
|
PageSize: 10,
|
||
|
Page: 0,
|
||
|
},
|
||
6 years ago
|
IncludeTags: false,
|
||
5 years ago
|
})
|
||
6 years ago
|
assert.NoError(t, err)
|
||
4 years ago
|
assert.Len(t, releases, 1)
|
||
6 years ago
|
|
||
|
issues, err := models.Issues(&models.IssuesOptions{
|
||
|
RepoIDs: []int64{repo.ID},
|
||
|
IsPull: util.OptionalBoolFalse,
|
||
|
SortType: "oldest",
|
||
|
})
|
||
|
assert.NoError(t, err)
|
||
3 years ago
|
assert.Len(t, issues, 15)
|
||
6 years ago
|
assert.NoError(t, issues[0].LoadDiscussComments())
|
||
4 years ago
|
assert.Empty(t, issues[0].Comments)
|
||
6 years ago
|
|
||
|
pulls, _, err := models.PullRequests(repo.ID, &models.PullRequestsOptions{
|
||
|
SortType: "oldest",
|
||
|
})
|
||
|
assert.NoError(t, err)
|
||
3 years ago
|
assert.Len(t, pulls, 30)
|
||
6 years ago
|
assert.NoError(t, pulls[0].LoadIssue())
|
||
|
assert.NoError(t, pulls[0].Issue.LoadDiscussComments())
|
||
4 years ago
|
assert.Len(t, pulls[0].Issue.Comments, 2)
|
||
6 years ago
|
}
|