Update Github Migration Tests (#8938)

Update all Github migration tests to use a new repo created just for
these tests that won't accidentially be modified by regular users
interacting with issues.

Fixes #8895
This commit is contained in:
mrsdizzie 2019-11-12 17:48:21 -05:00 committed by zeripath
parent 4b3fc74937
commit 3ddca774fc

View File

@ -14,7 +14,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func assertMilestoneEqual(t *testing.T, title, dueOn, created, updated, closed, state string, ms *base.Milestone) { func assertMilestoneEqual(t *testing.T, description, title, dueOn, created, updated, closed, state string, ms *base.Milestone) {
var tmPtr *time.Time var tmPtr *time.Time
if dueOn != "" { if dueOn != "" {
tm, err := time.Parse("2006-01-02 15:04:05 -0700 MST", dueOn) tm, err := time.Parse("2006-01-02 15:04:05 -0700 MST", dueOn)
@ -43,32 +43,34 @@ func assertMilestoneEqual(t *testing.T, title, dueOn, created, updated, closed,
} }
assert.EqualValues(t, &base.Milestone{ assert.EqualValues(t, &base.Milestone{
Title: title, Description: description,
Deadline: tmPtr, Title: title,
State: state, Deadline: tmPtr,
Created: createdTM, State: state,
Updated: updatedTM, Created: createdTM,
Closed: closedTM, Updated: updatedTM,
Closed: closedTM,
}, ms) }, ms)
} }
func assertLabelEqual(t *testing.T, name, color string, label *base.Label) { func assertLabelEqual(t *testing.T, name, color, description string, label *base.Label) {
assert.EqualValues(t, &base.Label{ assert.EqualValues(t, &base.Label{
Name: name, Name: name,
Color: color, Color: color,
Description: description,
}, label) }, label)
} }
func TestGitHubDownloadRepo(t *testing.T) { func TestGitHubDownloadRepo(t *testing.T) {
downloader := NewGithubDownloaderV3("", "", "go-gitea", "gitea") downloader := NewGithubDownloaderV3("", "", "go-gitea", "test_repo")
repo, err := downloader.GetRepoInfo() repo, err := downloader.GetRepoInfo()
assert.NoError(t, err) assert.NoError(t, err)
assert.EqualValues(t, &base.Repository{ assert.EqualValues(t, &base.Repository{
Name: "gitea", Name: "test_repo",
Owner: "go-gitea", Owner: "go-gitea",
Description: "Git with a cup of tea, painless self-hosted git service", Description: "Test repository for testing migration from github to gitea",
CloneURL: "https://github.com/go-gitea/gitea.git", CloneURL: "https://github.com/go-gitea/test_repo.git",
OriginalURL: "https://github.com/go-gitea/gitea", OriginalURL: "https://github.com/go-gitea/test_repo",
}, repo) }, repo)
topics, err := downloader.GetTopics() topics, err := downloader.GetTopics()
@ -77,77 +79,46 @@ func TestGitHubDownloadRepo(t *testing.T) {
milestones, err := downloader.GetMilestones() milestones, err := downloader.GetMilestones()
assert.NoError(t, err) assert.NoError(t, err)
// before this tool release, we have 39 milestones on github.com/go-gitea/gitea assert.True(t, len(milestones) >= 2)
assert.True(t, len(milestones) >= 39)
for _, milestone := range milestones { for _, milestone := range milestones {
switch milestone.Title { switch milestone.Title {
case "1.0.0": case "1.0.0":
assertMilestoneEqual(t, "1.0.0", "2016-12-23 08:00:00 +0000 UTC", assertMilestoneEqual(t, "Milestone 1.0.0", "1.0.0", "2019-11-11 08:00:00 +0000 UTC",
"2016-11-02 18:06:55 +0000 UTC", "2019-11-12 19:37:08 +0000 UTC",
"2016-12-29 10:26:00 +0000 UTC", "2019-11-12 21:56:17 +0000 UTC",
"2016-12-24 00:40:56 +0000 UTC", "2019-11-12 19:45:49 +0000 UTC",
"closed", milestone) "closed", milestone)
case "1.1.0": case "1.1.0":
assertMilestoneEqual(t, "1.1.0", "2017-02-24 08:00:00 +0000 UTC", assertMilestoneEqual(t, "Milestone 1.1.0", "1.1.0", "2019-11-12 08:00:00 +0000 UTC",
"2016-11-03 08:40:10 +0000 UTC", "2019-11-12 19:37:25 +0000 UTC",
"2017-06-15 05:04:36 +0000 UTC", "2019-11-12 21:39:27 +0000 UTC",
"2017-03-09 21:22:21 +0000 UTC", "2019-11-12 19:45:46 +0000 UTC",
"closed", milestone)
case "1.2.0":
assertMilestoneEqual(t, "1.2.0", "2017-04-24 07:00:00 +0000 UTC",
"2016-11-03 08:40:15 +0000 UTC",
"2017-12-10 02:43:29 +0000 UTC",
"2017-10-12 08:24:28 +0000 UTC",
"closed", milestone)
case "1.3.0":
assertMilestoneEqual(t, "1.3.0", "2017-11-29 08:00:00 +0000 UTC",
"2017-03-03 08:08:59 +0000 UTC",
"2017-12-04 07:48:44 +0000 UTC",
"2017-11-29 18:39:00 +0000 UTC",
"closed", milestone)
case "1.4.0":
assertMilestoneEqual(t, "1.4.0", "2018-01-25 08:00:00 +0000 UTC",
"2017-08-23 11:02:37 +0000 UTC",
"2018-03-25 20:01:56 +0000 UTC",
"2018-03-25 20:01:56 +0000 UTC",
"closed", milestone)
case "1.5.0":
assertMilestoneEqual(t, "1.5.0", "2018-06-15 07:00:00 +0000 UTC",
"2017-12-30 04:21:56 +0000 UTC",
"2018-09-05 16:34:22 +0000 UTC",
"2018-08-11 08:45:01 +0000 UTC",
"closed", milestone)
case "1.7.0":
assertMilestoneEqual(t, "1.7.0", "2018-12-25 08:00:00 +0000 UTC",
"2018-08-28 14:20:14 +0000 UTC",
"2019-01-27 11:30:24 +0000 UTC",
"2019-01-23 08:58:23 +0000 UTC",
"closed", milestone) "closed", milestone)
} }
} }
labels, err := downloader.GetLabels() labels, err := downloader.GetLabels()
assert.NoError(t, err) assert.NoError(t, err)
assert.True(t, len(labels) >= 48) assert.True(t, len(labels) >= 8)
for _, l := range labels { for _, l := range labels {
switch l.Name { switch l.Name {
case "backport/v1.7": case "bug":
assertLabelEqual(t, "backport/v1.7", "fbca04", l) assertLabelEqual(t, "bug", "d73a4a", "Something isn't working", l)
case "backport/v1.8": case "documentation":
assertLabelEqual(t, "backport/v1.8", "fbca04", l) assertLabelEqual(t, "documentation", "0075ca", "Improvements or additions to documentation", l)
case "kind/api": case "duplicate":
assertLabelEqual(t, "kind/api", "5319e7", l) assertLabelEqual(t, "duplicate", "cfd3d7", "This issue or pull request already exists", l)
case "kind/breaking": case "enhancement":
assertLabelEqual(t, "kind/breaking", "fbca04", l) assertLabelEqual(t, "enhancement", "a2eeef", "New feature or request", l)
case "kind/bug": case "good first issue":
assertLabelEqual(t, "kind/bug", "ee0701", l) assertLabelEqual(t, "good first issue", "7057ff", "Good for newcomers", l)
case "kind/docs": case "help wanted":
assertLabelEqual(t, "kind/docs", "c2e0c6", l) assertLabelEqual(t, "help wanted", "008672", "Extra attention is needed", l)
case "kind/enhancement": case "invalid":
assertLabelEqual(t, "kind/enhancement", "84b6eb", l) assertLabelEqual(t, "invalid", "e4e669", "This doesn't seem right", l)
case "kind/feature": case "question":
assertLabelEqual(t, "kind/feature", "006b75", l) assertLabelEqual(t, "question", "d876e3", "Further information is requested", l)
} }
} }
@ -157,48 +128,50 @@ func TestGitHubDownloadRepo(t *testing.T) {
{ {
TagName: "v0.9.99", TagName: "v0.9.99",
TargetCommitish: "master", TargetCommitish: "master",
Name: "fork", Name: "First Release",
Body: "Forked source from Gogs into Gitea\n", Body: "A test release",
Created: time.Date(2016, 10, 17, 02, 17, 59, 0, time.UTC), Created: time.Date(2019, 11, 9, 16, 49, 21, 0, time.UTC),
Published: time.Date(2016, 11, 17, 15, 37, 0, 0, time.UTC), Published: time.Date(2019, 11, 12, 20, 12, 10, 0, time.UTC),
PublisherID: 4726179, PublisherID: 1669571,
PublisherName: "bkcsoft", PublisherName: "mrsdizzie",
}, },
}, releases[len(releases)-1:]) }, releases[len(releases)-1:])
// downloader.GetIssues() // downloader.GetIssues()
issues, isEnd, err := downloader.GetIssues(1, 8) issues, isEnd, err := downloader.GetIssues(1, 2)
assert.NoError(t, err) assert.NoError(t, err)
assert.EqualValues(t, 3, len(issues)) assert.EqualValues(t, 2, len(issues))
assert.False(t, isEnd) assert.False(t, isEnd)
var ( var (
closed1 = time.Date(2018, 10, 23, 02, 57, 43, 0, time.UTC) closed1 = time.Date(2019, 11, 12, 20, 22, 22, 0, time.UTC)
closed7 = time.Date(2019, 7, 8, 8, 20, 23, 0, time.UTC) closed2 = time.Date(2019, 11, 12, 21, 1, 31, 0, time.UTC)
) )
assert.EqualValues(t, []*base.Issue{ assert.EqualValues(t, []*base.Issue{
{ {
Number: 6, Number: 1,
Title: "Contribution system: History heatmap for user", Title: "Please add an animated gif icon to the merge button",
Content: "Hi guys,\r\n\r\nI think that is a possible feature, a history heatmap similar to github or gitlab.\r\nActually exists a plugin called Calendar HeatMap. I used this on mine project to heat application log and worked fine here.\r\nThen, is only a idea, what you think? :)\r\n\r\nhttp://cal-heatmap.com/\r\nhttps://github.com/wa0x6e/cal-heatmap\r\n\r\nReference: https://github.com/gogits/gogs/issues/1640", Content: "I just want the merge button to hurt my eyes a little. \xF0\x9F\x98\x9D ",
Milestone: "1.7.0", Milestone: "1.0.0",
PosterID: 1520407, PosterID: 18600385,
PosterName: "joubertredrat", PosterName: "guillep2k",
State: "closed", State: "closed",
Created: time.Date(2016, 11, 02, 18, 51, 55, 0, time.UTC), Created: time.Date(2019, 11, 9, 17, 0, 29, 0, time.UTC),
Labels: []*base.Label{ Labels: []*base.Label{
{ {
Name: "kind/feature", Name: "bug",
Color: "006b75", Color: "d73a4a",
Description: "Something isn't working",
}, },
{ {
Name: "kind/ui", Name: "good first issue",
Color: "fef2c0", Color: "7057ff",
Description: "Good for newcomers",
}, },
}, },
Reactions: &base.Reactions{ Reactions: &base.Reactions{
TotalCount: 0, TotalCount: 1,
PlusOne: 0, PlusOne: 1,
MinusOne: 0, MinusOne: 0,
Laugh: 0, Laugh: 0,
Confused: 0, Confused: 0,
@ -208,84 +181,48 @@ func TestGitHubDownloadRepo(t *testing.T) {
Closed: &closed1, Closed: &closed1,
}, },
{ {
Number: 7, Number: 2,
Title: "display page revisions on wiki", Title: "Test issue",
Content: "Hi guys,\r\n\r\nWiki on Gogs is very fine, I liked a lot, but I think that is good idea to be possible see other revisions from page as a page history.\r\n\r\nWhat you think?\r\n\r\nReference: https://github.com/gogits/gogs/issues/2991", Content: "This is test issue 2, do not touch!",
Milestone: "1.10.0", Milestone: "1.1.0",
PosterID: 1520407, PosterID: 1669571,
PosterName: "joubertredrat", PosterName: "mrsdizzie",
State: "closed", State: "closed",
Created: time.Date(2016, 11, 02, 18, 57, 32, 0, time.UTC), Created: time.Date(2019, 11, 12, 21, 0, 6, 0, time.UTC),
Labels: []*base.Label{ Labels: []*base.Label{
{ {
Name: "kind/feature", Name: "duplicate",
Color: "006b75", Color: "cfd3d7",
}, Description: "This issue or pull request already exists",
{
Name: "reviewed/confirmed",
Color: "8d9b12",
Description: "Issue has been reviewed and confirmed to be present or accepted to be implemented",
}, },
}, },
Reactions: &base.Reactions{ Reactions: &base.Reactions{
TotalCount: 6, TotalCount: 6,
PlusOne: 5, PlusOne: 1,
MinusOne: 0, MinusOne: 1,
Laugh: 0, Laugh: 1,
Confused: 1, Confused: 1,
Heart: 0,
Hooray: 0,
},
Closed: &closed7,
},
{
Number: 8,
Title: "audit logs",
Content: "Hi,\r\n\r\nI think that is good idea to have user operation log to admin see what the user is doing at Gogs. Similar to example below\r\n\r\n| user | operation | information |\r\n| --- | --- | --- |\r\n| joubertredrat | repo.create | Create repo MyProjectData |\r\n| joubertredrat | user.settings | Edit settings |\r\n| tboerger | repo.fork | Create Fork from MyProjectData to ForkMyProjectData |\r\n| bkcsoft | repo.remove | Remove repo MySource |\r\n| tboerger | admin.auth | Edit auth LDAP org-connection |\r\n\r\nThis resource can be used on user page too, as user activity, set that log row is public (repo._) or private (user._, admin.*) and display only public activity.\r\n\r\nWhat you think?\r\n\r\n[Chat summary from March 14, 2017](https://github.com/go-gitea/gitea/issues/8#issuecomment-286463807)\r\n\r\nReferences:\r\nhttps://github.com/gogits/gogs/issues/3016",
Milestone: "1.x.x",
PosterID: 1520407,
PosterName: "joubertredrat",
State: "open",
Created: time.Date(2016, 11, 02, 18, 59, 20, 0, time.UTC),
Labels: []*base.Label{
{
Name: "kind/feature",
Color: "006b75",
},
{
Name: "kind/proposal",
Color: "5319e7",
},
},
Reactions: &base.Reactions{
TotalCount: 9,
PlusOne: 8,
MinusOne: 0,
Laugh: 0,
Confused: 0,
Heart: 1, Heart: 1,
Hooray: 0, Hooray: 1,
}, },
Closed: &closed2,
}, },
}, issues) }, issues)
// downloader.GetComments() // downloader.GetComments()
comments, err := downloader.GetComments(6) comments, err := downloader.GetComments(2)
assert.NoError(t, err) assert.NoError(t, err)
assert.EqualValues(t, 35, len(comments)) assert.EqualValues(t, 2, len(comments))
assert.EqualValues(t, []*base.Comment{ assert.EqualValues(t, []*base.Comment{
{ {
IssueIndex: 6, IssueIndex: 2,
PosterID: 4726179, PosterID: 1669571,
PosterName: "bkcsoft", PosterName: "mrsdizzie",
Created: time.Date(2016, 11, 02, 18, 59, 48, 0, time.UTC), Created: time.Date(2019, 11, 12, 21, 0, 13, 0, time.UTC),
Content: `I would prefer a solution that is in the backend, unless it's required to have it update without reloading. Unfortunately I can't seem to find anything that does that :unamused: Content: "This is a comment",
Also this would _require_ caching, since it will fetch huge amounts of data from disk...
`,
Reactions: &base.Reactions{ Reactions: &base.Reactions{
TotalCount: 2, TotalCount: 1,
PlusOne: 2, PlusOne: 1,
MinusOne: 0, MinusOne: 0,
Laugh: 0, Laugh: 0,
Confused: 0, Confused: 0,
@ -294,14 +231,11 @@ Also this would _require_ caching, since it will fetch huge amounts of data from
}, },
}, },
{ {
IssueIndex: 6, IssueIndex: 2,
PosterID: 1520407, PosterID: 1669571,
PosterName: "joubertredrat", PosterName: "mrsdizzie",
Created: time.Date(2016, 11, 02, 19, 16, 56, 0, time.UTC), Created: time.Date(2019, 11, 12, 22, 7, 14, 0, time.UTC),
Content: `Yes, this plugin build on front-end, with backend I don't know too, but we can consider make component for this. Content: "A second comment",
In my case I use ajax to get data, but build on frontend anyway
`,
Reactions: &base.Reactions{ Reactions: &base.Reactions{
TotalCount: 0, TotalCount: 0,
PlusOne: 0, PlusOne: 0,
@ -312,154 +246,85 @@ In my case I use ajax to get data, but build on frontend anyway
Hooray: 0, Hooray: 0,
}, },
}, },
{ }, comments[:2])
IssueIndex: 6,
PosterID: 1799009,
PosterName: "xinity",
Created: time.Date(2016, 11, 03, 13, 04, 56, 0, time.UTC),
Content: `following @bkcsoft retention strategy in cache is a must if we don't want gitea to waste ressources.
something like in the latest 15days could be enough don't you think ?
`,
Reactions: &base.Reactions{
TotalCount: 2,
PlusOne: 2,
MinusOne: 0,
Laugh: 0,
Confused: 0,
Heart: 0,
Hooray: 0,
},
},
}, comments[:3])
// downloader.GetPullRequests() // downloader.GetPullRequests()
prs, err := downloader.GetPullRequests(1, 3) prs, err := downloader.GetPullRequests(1, 2)
assert.NoError(t, err) assert.NoError(t, err)
assert.EqualValues(t, 3, len(prs)) assert.EqualValues(t, 2, len(prs))
closed1 = time.Date(2016, 11, 02, 18, 22, 21, 0, time.UTC) closed1 = time.Date(2019, 11, 12, 21, 39, 27, 0, time.UTC)
var ( var merged1 = time.Date(2019, 11, 12, 21, 39, 27, 0, time.UTC)
closed2 = time.Date(2016, 11, 03, 8, 06, 27, 0, time.UTC)
closed3 = time.Date(2016, 11, 02, 18, 22, 31, 0, time.UTC)
)
var (
merged1 = time.Date(2016, 11, 02, 18, 22, 21, 0, time.UTC)
merged2 = time.Date(2016, 11, 03, 8, 06, 27, 0, time.UTC)
merged3 = time.Date(2016, 11, 02, 18, 22, 31, 0, time.UTC)
)
assert.EqualValues(t, []*base.PullRequest{ assert.EqualValues(t, []*base.PullRequest{
{ {
Number: 1, Number: 3,
Title: "Rename import paths: \"github.com/gogits/gogs\" -> \"github.com/go-gitea/gitea\"", Title: "Update README.md",
Content: "", Content: "add warning to readme",
Milestone: "1.0.0", Milestone: "1.1.0",
PosterID: 7011819, PosterID: 1669571,
PosterName: "andreynering", PosterName: "mrsdizzie",
State: "closed", State: "closed",
Created: time.Date(2016, 11, 02, 17, 01, 19, 0, time.UTC), Created: time.Date(2019, 11, 12, 21, 21, 43, 0, time.UTC),
Labels: []*base.Label{ Labels: []*base.Label{
{ {
Name: "kind/enhancement", Name: "documentation",
Color: "84b6eb", Color: "0075ca",
}, Description: "Improvements or additions to documentation",
{
Name: "lgtm/done",
Color: "0e8a16",
}, },
}, },
PatchURL: "https://github.com/go-gitea/gitea/pull/1.patch", PatchURL: "https://github.com/go-gitea/test_repo/pull/3.patch",
Head: base.PullRequestBranch{ Head: base.PullRequestBranch{
Ref: "import-paths", Ref: "master",
SHA: "1b0ec3208db8501acba44a137c009a5a126ebaa9", CloneURL: "https://github.com/mrsdizzie/test_repo.git",
OwnerName: "andreynering", SHA: "076160cf0b039f13e5eff19619932d181269414b",
RepoName: "test_repo",
OwnerName: "mrsdizzie",
}, },
Base: base.PullRequestBranch{ Base: base.PullRequestBranch{
Ref: "master", Ref: "master",
SHA: "6bcff7828f117af8d51285ce3acba01a7e40a867", SHA: "72866af952e98d02a73003501836074b286a78f6",
OwnerName: "go-gitea", OwnerName: "go-gitea",
RepoName: "gitea", RepoName: "test_repo",
}, },
Closed: &closed1, Closed: &closed1,
Merged: true, Merged: true,
MergedTime: &merged1, MergedTime: &merged1,
MergeCommitSHA: "142d35e8d2baec230ddb565d1265940d59141fab", MergeCommitSHA: "f32b0a9dfd09a60f616f29158f772cedd89942d2",
}, },
{ {
Number: 2, Number: 4,
Title: "Fix sender of issue notifications", Title: "Test branch",
Content: "It is the FROM field in mailer configuration that needs be used,\r\nnot the USER field, which is for authentication.\r\n\r\nMigrated from https://github.com/gogits/gogs/pull/3616\r\n", Content: "do not merge this PR",
Milestone: "1.0.0", Milestone: "1.0.0",
PosterID: 289678, PosterID: 1669571,
PosterName: "strk", PosterName: "mrsdizzie",
State: "closed", State: "open",
Created: time.Date(2016, 11, 02, 17, 24, 19, 0, time.UTC), Created: time.Date(2019, 11, 12, 21, 54, 18, 0, time.UTC),
Labels: []*base.Label{ Labels: []*base.Label{
{ {
Name: "kind/bug", Name: "bug",
Color: "ee0701", Color: "d73a4a",
}, Description: "Something isn't working",
{
Name: "lgtm/done",
Color: "0e8a16",
}, },
}, },
PatchURL: "https://github.com/go-gitea/gitea/pull/2.patch", PatchURL: "https://github.com/go-gitea/test_repo/pull/4.patch",
Head: base.PullRequestBranch{ Head: base.PullRequestBranch{
Ref: "proper-from-on-issue-mail", Ref: "test-branch",
SHA: "af03d00780a6ee70c58e135c6679542cde4f8d50", SHA: "2be9101c543658591222acbee3eb799edfc3853d",
RepoName: "gogs", RepoName: "test_repo",
OwnerName: "strk", OwnerName: "mrsdizzie",
CloneURL: "https://github.com/strk/gogs.git", CloneURL: "https://github.com/mrsdizzie/test_repo.git",
}, },
Base: base.PullRequestBranch{ Base: base.PullRequestBranch{
Ref: "develop", Ref: "master",
SHA: "5c5424301443ffa3659737d12de48ab1dfe39a00", SHA: "f32b0a9dfd09a60f616f29158f772cedd89942d2",
OwnerName: "go-gitea", OwnerName: "go-gitea",
RepoName: "gitea", RepoName: "test_repo",
}, },
Closed: &closed2, Merged: false,
Merged: true, MergeCommitSHA: "565d1208f5fffdc1c5ae1a2436491eb9a5e4ebae",
MergedTime: &merged2,
MergeCommitSHA: "d8de2beb5b92d02a0597ba7c7803839380666653",
},
{
Number: 3,
Title: "Use proper url for libravatar dep",
Content: "Fetch go-libravatar from its official source, rather than from an unmaintained fork\r\n",
Milestone: "1.0.0",
PosterID: 289678,
PosterName: "strk",
State: "closed",
Created: time.Date(2016, 11, 02, 17, 34, 31, 0, time.UTC),
Labels: []*base.Label{
{
Name: "kind/enhancement",
Color: "84b6eb",
},
{
Name: "lgtm/done",
Color: "0e8a16",
},
},
PatchURL: "https://github.com/go-gitea/gitea/pull/3.patch",
Head: base.PullRequestBranch{
Ref: "libravatar-proper-url",
SHA: "d59a48a2550abd4129b96d38473941b895a4859b",
RepoName: "gogs",
OwnerName: "strk",
CloneURL: "https://github.com/strk/gogs.git",
},
Base: base.PullRequestBranch{
Ref: "develop",
SHA: "6bcff7828f117af8d51285ce3acba01a7e40a867",
OwnerName: "go-gitea",
RepoName: "gitea",
},
Closed: &closed3,
Merged: true,
MergedTime: &merged3,
MergeCommitSHA: "5c5424301443ffa3659737d12de48ab1dfe39a00",
}, },
}, prs) }, prs)
} }