2021-01-21 19:33:58 +00:00
|
|
|
// Copyright 2019 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 migrations
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2021-11-16 15:25:33 +00:00
|
|
|
base "code.gitea.io/gitea/modules/migration"
|
2021-01-21 19:33:58 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGogsDownloadRepo(t *testing.T) {
|
|
|
|
// Skip tests if Gogs token is not found
|
|
|
|
gogsPersonalAccessToken := os.Getenv("GOGS_READ_TOKEN")
|
|
|
|
if len(gogsPersonalAccessToken) == 0 {
|
|
|
|
t.Skip("skipped test because GOGS_READ_TOKEN was not in the environment")
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := http.Get("https://try.gogs.io/lunnytest/TESTREPO")
|
|
|
|
if err != nil || resp.StatusCode/100 != 2 {
|
|
|
|
// skip and don't run test
|
|
|
|
t.Skipf("visit test repo failed, ignored")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
downloader := NewGogsDownloader(context.Background(), "https://try.gogs.io", "", "", gogsPersonalAccessToken, "lunnytest", "TESTREPO")
|
|
|
|
repo, err := downloader.GetRepoInfo()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-08-18 00:47:18 +00:00
|
|
|
assertRepositoryEqual(t, &base.Repository{
|
|
|
|
Name: "TESTREPO",
|
|
|
|
Owner: "lunnytest",
|
|
|
|
Description: "",
|
|
|
|
CloneURL: "https://try.gogs.io/lunnytest/TESTREPO.git",
|
|
|
|
OriginalURL: "https://try.gogs.io/lunnytest/TESTREPO",
|
|
|
|
DefaultBranch: "master",
|
2021-01-21 19:33:58 +00:00
|
|
|
}, repo)
|
|
|
|
|
|
|
|
milestones, err := downloader.GetMilestones()
|
|
|
|
assert.NoError(t, err)
|
2021-08-18 00:47:18 +00:00
|
|
|
assertMilestonesEqual(t, []*base.Milestone{
|
|
|
|
{
|
|
|
|
Title: "1.0",
|
|
|
|
State: "open",
|
|
|
|
},
|
|
|
|
}, milestones)
|
2021-01-21 19:33:58 +00:00
|
|
|
|
|
|
|
labels, err := downloader.GetLabels()
|
|
|
|
assert.NoError(t, err)
|
2021-08-18 00:47:18 +00:00
|
|
|
assertLabelsEqual(t, []*base.Label{
|
|
|
|
{
|
|
|
|
Name: "bug",
|
|
|
|
Color: "ee0701",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "duplicate",
|
|
|
|
Color: "cccccc",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "enhancement",
|
|
|
|
Color: "84b6eb",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "help wanted",
|
|
|
|
Color: "128a0c",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "invalid",
|
|
|
|
Color: "e6e6e6",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "question",
|
|
|
|
Color: "cc317c",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "wontfix",
|
|
|
|
Color: "ffffff",
|
|
|
|
},
|
|
|
|
}, labels)
|
2021-01-21 19:33:58 +00:00
|
|
|
|
|
|
|
// downloader.GetIssues()
|
|
|
|
issues, isEnd, err := downloader.GetIssues(1, 8)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.False(t, isEnd)
|
2021-08-18 00:47:18 +00:00
|
|
|
assertIssuesEqual(t, []*base.Issue{
|
2021-01-21 19:33:58 +00:00
|
|
|
{
|
|
|
|
Number: 1,
|
2021-08-18 00:47:18 +00:00
|
|
|
PosterID: 5331,
|
|
|
|
PosterName: "lunny",
|
|
|
|
PosterEmail: "xiaolunwen@gmail.com",
|
2021-01-21 19:33:58 +00:00
|
|
|
Title: "test",
|
|
|
|
Content: "test",
|
|
|
|
Milestone: "",
|
|
|
|
State: "open",
|
|
|
|
Created: time.Date(2019, 06, 11, 8, 16, 44, 0, time.UTC),
|
2021-08-18 00:47:18 +00:00
|
|
|
Updated: time.Date(2019, 10, 26, 11, 07, 2, 0, time.UTC),
|
2021-01-21 19:33:58 +00:00
|
|
|
Labels: []*base.Label{
|
|
|
|
{
|
|
|
|
Name: "bug",
|
|
|
|
Color: "ee0701",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, issues)
|
|
|
|
|
|
|
|
// downloader.GetComments()
|
2021-06-30 07:23:49 +00:00
|
|
|
comments, _, err := downloader.GetComments(base.GetCommentOptions{
|
2021-08-21 22:47:45 +00:00
|
|
|
Context: base.BasicIssueContext(1),
|
2021-06-30 07:23:49 +00:00
|
|
|
})
|
2021-01-21 19:33:58 +00:00
|
|
|
assert.NoError(t, err)
|
2021-08-18 00:47:18 +00:00
|
|
|
assertCommentsEqual(t, []*base.Comment{
|
2021-01-21 19:33:58 +00:00
|
|
|
{
|
2021-08-18 00:47:18 +00:00
|
|
|
IssueIndex: 1,
|
|
|
|
PosterID: 5331,
|
2021-01-21 19:33:58 +00:00
|
|
|
PosterName: "lunny",
|
|
|
|
PosterEmail: "xiaolunwen@gmail.com",
|
|
|
|
Created: time.Date(2019, 06, 11, 8, 19, 50, 0, time.UTC),
|
|
|
|
Updated: time.Date(2019, 06, 11, 8, 19, 50, 0, time.UTC),
|
2021-08-18 00:47:18 +00:00
|
|
|
Content: "1111",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
IssueIndex: 1,
|
|
|
|
PosterID: 15822,
|
|
|
|
PosterName: "clacplouf",
|
|
|
|
PosterEmail: "test1234@dbn.re",
|
|
|
|
Created: time.Date(2019, 10, 26, 11, 7, 2, 0, time.UTC),
|
|
|
|
Updated: time.Date(2019, 10, 26, 11, 7, 2, 0, time.UTC),
|
|
|
|
Content: "88888888",
|
2021-01-21 19:33:58 +00:00
|
|
|
},
|
|
|
|
}, comments)
|
|
|
|
|
|
|
|
// downloader.GetPullRequests()
|
|
|
|
_, _, err = downloader.GetPullRequests(1, 3)
|
|
|
|
assert.Error(t, err)
|
|
|
|
}
|