A fork of Gitea (see branch `mj`) adding Majority Judgment Polls 𐄷 over Issues and Merge Requests. https://git.mieuxvoter.fr
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.

122 lines
3.1 KiB

  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. package migrations
  5. import (
  6. "context"
  7. "net/http"
  8. "os"
  9. "testing"
  10. "time"
  11. "code.gitea.io/gitea/modules/migrations/base"
  12. "github.com/stretchr/testify/assert"
  13. )
  14. func TestGogsDownloadRepo(t *testing.T) {
  15. // Skip tests if Gogs token is not found
  16. gogsPersonalAccessToken := os.Getenv("GOGS_READ_TOKEN")
  17. if len(gogsPersonalAccessToken) == 0 {
  18. t.Skip("skipped test because GOGS_READ_TOKEN was not in the environment")
  19. }
  20. resp, err := http.Get("https://try.gogs.io/lunnytest/TESTREPO")
  21. if err != nil || resp.StatusCode/100 != 2 {
  22. // skip and don't run test
  23. t.Skipf("visit test repo failed, ignored")
  24. return
  25. }
  26. downloader := NewGogsDownloader(context.Background(), "https://try.gogs.io", "", "", gogsPersonalAccessToken, "lunnytest", "TESTREPO")
  27. repo, err := downloader.GetRepoInfo()
  28. assert.NoError(t, err)
  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. milestones, err := downloader.GetMilestones()
  36. assert.NoError(t, err)
  37. assert.True(t, len(milestones) == 1)
  38. for _, milestone := range milestones {
  39. switch milestone.Title {
  40. case "1.0":
  41. assert.EqualValues(t, "open", milestone.State)
  42. }
  43. }
  44. labels, err := downloader.GetLabels()
  45. assert.NoError(t, err)
  46. assert.Len(t, labels, 7)
  47. for _, l := range labels {
  48. switch l.Name {
  49. case "bug":
  50. assertLabelEqual(t, "bug", "ee0701", "", l)
  51. case "duplicated":
  52. assertLabelEqual(t, "duplicated", "cccccc", "", l)
  53. case "enhancement":
  54. assertLabelEqual(t, "enhancement", "84b6eb", "", l)
  55. case "help wanted":
  56. assertLabelEqual(t, "help wanted", "128a0c", "", l)
  57. case "invalid":
  58. assertLabelEqual(t, "invalid", "e6e6e6", "", l)
  59. case "question":
  60. assertLabelEqual(t, "question", "cc317c", "", l)
  61. case "wontfix":
  62. assertLabelEqual(t, "wontfix", "ffffff", "", l)
  63. }
  64. }
  65. _, err = downloader.GetReleases()
  66. assert.Error(t, err)
  67. // downloader.GetIssues()
  68. issues, isEnd, err := downloader.GetIssues(1, 8)
  69. assert.NoError(t, err)
  70. assert.EqualValues(t, 1, len(issues))
  71. assert.False(t, isEnd)
  72. assert.EqualValues(t, []*base.Issue{
  73. {
  74. Number: 1,
  75. Title: "test",
  76. Content: "test",
  77. Milestone: "",
  78. PosterName: "lunny",
  79. PosterEmail: "xiaolunwen@gmail.com",
  80. State: "open",
  81. Created: time.Date(2019, 06, 11, 8, 16, 44, 0, time.UTC),
  82. Labels: []*base.Label{
  83. {
  84. Name: "bug",
  85. Color: "ee0701",
  86. },
  87. },
  88. },
  89. }, issues)
  90. // downloader.GetComments()
  91. comments, err := downloader.GetComments(1)
  92. assert.NoError(t, err)
  93. assert.EqualValues(t, 1, len(comments))
  94. assert.EqualValues(t, []*base.Comment{
  95. {
  96. PosterName: "lunny",
  97. PosterEmail: "xiaolunwen@gmail.com",
  98. Created: time.Date(2019, 06, 11, 8, 19, 50, 0, time.UTC),
  99. Updated: time.Date(2019, 06, 11, 8, 19, 50, 0, time.UTC),
  100. Content: `1111`,
  101. },
  102. }, comments)
  103. // downloader.GetPullRequests()
  104. _, _, err = downloader.GetPullRequests(1, 3)
  105. assert.Error(t, err)
  106. }