|
| 1 | +// Copyright 2019 The Gitea Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a MIT-style |
| 3 | +// license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +package migrations |
| 6 | + |
| 7 | +import ( |
| 8 | + "net/http" |
| 9 | + "testing" |
| 10 | + "time" |
| 11 | + |
| 12 | + "code.gitea.io/gitea/modules/migrations/base" |
| 13 | + |
| 14 | + "github.com/stretchr/testify/assert" |
| 15 | +) |
| 16 | + |
| 17 | +func TestGogsDownloadRepo(t *testing.T) { |
| 18 | + resp, err := http.Get("https://try.gogs.io/lunnytest/TESTREPO") |
| 19 | + if err != nil || resp.StatusCode/100 != 2 { |
| 20 | + // skip and don't run test |
| 21 | + t.Skipf("visit test repo failed, ignored") |
| 22 | + return |
| 23 | + } |
| 24 | + |
| 25 | + downloader := NewGogsDownloader("https://try.gogs.io", "c109b3c905eb57951cfdea270cfcfdc297a74500", "", "lunnytest", "TESTREPO") |
| 26 | + repo, err := downloader.GetRepoInfo() |
| 27 | + assert.NoError(t, err) |
| 28 | + |
| 29 | + assert.EqualValues(t, &base.Repository{ |
| 30 | + Name: "TESTREPO", |
| 31 | + Owner: "lunnytest", |
| 32 | + Description: "", |
| 33 | + CloneURL: "https://try.gogs.io/lunnytest/TESTREPO.git", |
| 34 | + }, repo) |
| 35 | + |
| 36 | + milestones, err := downloader.GetMilestones() |
| 37 | + assert.NoError(t, err) |
| 38 | + assert.True(t, len(milestones) == 1) |
| 39 | + |
| 40 | + for _, milestone := range milestones { |
| 41 | + switch milestone.Title { |
| 42 | + case "1.0": |
| 43 | + assert.EqualValues(t, "open", milestone.State) |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + labels, err := downloader.GetLabels() |
| 48 | + assert.NoError(t, err) |
| 49 | + assert.True(t, len(labels) == 7) |
| 50 | + for _, l := range labels { |
| 51 | + switch l.Name { |
| 52 | + case "bug": |
| 53 | + assertLabelEqual(t, "bug", "ee0701", l) |
| 54 | + case "duplicated": |
| 55 | + assertLabelEqual(t, "duplicated", "cccccc", l) |
| 56 | + case "enhancement": |
| 57 | + assertLabelEqual(t, "enhancement", "84b6eb", l) |
| 58 | + case "help wanted": |
| 59 | + assertLabelEqual(t, "help wanted", "128a0c", l) |
| 60 | + case "invalid": |
| 61 | + assertLabelEqual(t, "invalid", "e6e6e6", l) |
| 62 | + case "question": |
| 63 | + assertLabelEqual(t, "question", "cc317c", l) |
| 64 | + case "wontfix": |
| 65 | + assertLabelEqual(t, "wontfix", "ffffff", l) |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + _, err = downloader.GetReleases() |
| 70 | + assert.Error(t, err) |
| 71 | + |
| 72 | + // downloader.GetIssues() |
| 73 | + issues, isEnd, err := downloader.GetIssues(1, 8) |
| 74 | + assert.NoError(t, err) |
| 75 | + assert.EqualValues(t, 1, len(issues)) |
| 76 | + assert.False(t, isEnd) |
| 77 | + |
| 78 | + assert.EqualValues(t, []*base.Issue{ |
| 79 | + { |
| 80 | + Number: 1, |
| 81 | + Title: "test", |
| 82 | + Content: "test", |
| 83 | + Milestone: "", |
| 84 | + PosterName: "lunny", |
| 85 | + PosterEmail: "xiaolunwen@gmail.com", |
| 86 | + State: "open", |
| 87 | + Created: time.Date(2019, 06, 11, 8, 16, 44, 0, time.UTC), |
| 88 | + Labels: []*base.Label{ |
| 89 | + { |
| 90 | + Name: "bug", |
| 91 | + Color: "ee0701", |
| 92 | + }, |
| 93 | + }, |
| 94 | + }, |
| 95 | + }, issues) |
| 96 | + |
| 97 | + // downloader.GetComments() |
| 98 | + comments, err := downloader.GetComments(1) |
| 99 | + assert.NoError(t, err) |
| 100 | + assert.EqualValues(t, 1, len(comments)) |
| 101 | + assert.EqualValues(t, []*base.Comment{ |
| 102 | + { |
| 103 | + PosterName: "lunny", |
| 104 | + PosterEmail: "xiaolunwen@gmail.com", |
| 105 | + Created: time.Date(2019, 06, 11, 8, 19, 50, 0, time.UTC), |
| 106 | + Updated: time.Date(2019, 06, 11, 8, 19, 50, 0, time.UTC), |
| 107 | + Content: `1111`, |
| 108 | + }, |
| 109 | + }, comments) |
| 110 | + |
| 111 | + // downloader.GetPullRequests() |
| 112 | + _, err = downloader.GetPullRequests(1, 3) |
| 113 | + assert.Error(t, err) |
| 114 | +} |
0 commit comments