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.

gogs_test.go 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package migrations
  4. import (
  5. "context"
  6. "net/http"
  7. "os"
  8. "testing"
  9. "time"
  10. base "code.gitea.io/gitea/modules/migration"
  11. "github.com/stretchr/testify/assert"
  12. )
  13. func TestGogsDownloadRepo(t *testing.T) {
  14. // Skip tests if Gogs token is not found
  15. gogsPersonalAccessToken := os.Getenv("GOGS_READ_TOKEN")
  16. if len(gogsPersonalAccessToken) == 0 {
  17. t.Skip("skipped test because GOGS_READ_TOKEN was not in the environment")
  18. }
  19. resp, err := http.Get("https://try.gogs.io/lunnytest/TESTREPO")
  20. if err != nil || resp.StatusCode/100 != 2 {
  21. // skip and don't run test
  22. t.Skipf("visit test repo failed, ignored")
  23. return
  24. }
  25. downloader := NewGogsDownloader(context.Background(), "https://try.gogs.io", "", "", gogsPersonalAccessToken, "lunnytest", "TESTREPO")
  26. repo, err := downloader.GetRepoInfo()
  27. assert.NoError(t, err)
  28. assertRepositoryEqual(t, &base.Repository{
  29. Name: "TESTREPO",
  30. Owner: "lunnytest",
  31. Description: "",
  32. CloneURL: "https://try.gogs.io/lunnytest/TESTREPO.git",
  33. OriginalURL: "https://try.gogs.io/lunnytest/TESTREPO",
  34. DefaultBranch: "master",
  35. }, repo)
  36. milestones, err := downloader.GetMilestones()
  37. assert.NoError(t, err)
  38. assertMilestonesEqual(t, []*base.Milestone{
  39. {
  40. Title: "1.0",
  41. State: "open",
  42. },
  43. }, milestones)
  44. labels, err := downloader.GetLabels()
  45. assert.NoError(t, err)
  46. assertLabelsEqual(t, []*base.Label{
  47. {
  48. Name: "bug",
  49. Color: "ee0701",
  50. },
  51. {
  52. Name: "duplicate",
  53. Color: "cccccc",
  54. },
  55. {
  56. Name: "enhancement",
  57. Color: "84b6eb",
  58. },
  59. {
  60. Name: "help wanted",
  61. Color: "128a0c",
  62. },
  63. {
  64. Name: "invalid",
  65. Color: "e6e6e6",
  66. },
  67. {
  68. Name: "question",
  69. Color: "cc317c",
  70. },
  71. {
  72. Name: "wontfix",
  73. Color: "ffffff",
  74. },
  75. }, labels)
  76. // downloader.GetIssues()
  77. issues, isEnd, err := downloader.GetIssues(1, 8)
  78. assert.NoError(t, err)
  79. assert.False(t, isEnd)
  80. assertIssuesEqual(t, []*base.Issue{
  81. {
  82. Number: 1,
  83. PosterID: 5331,
  84. PosterName: "lunny",
  85. PosterEmail: "xiaolunwen@gmail.com",
  86. Title: "test",
  87. Content: "test",
  88. Milestone: "",
  89. State: "open",
  90. Created: time.Date(2019, 6, 11, 8, 16, 44, 0, time.UTC),
  91. Updated: time.Date(2019, 10, 26, 11, 7, 2, 0, time.UTC),
  92. Labels: []*base.Label{
  93. {
  94. Name: "bug",
  95. Color: "ee0701",
  96. },
  97. },
  98. },
  99. }, issues)
  100. // downloader.GetComments()
  101. comments, _, err := downloader.GetComments(&base.Issue{Number: 1, ForeignIndex: 1})
  102. assert.NoError(t, err)
  103. assertCommentsEqual(t, []*base.Comment{
  104. {
  105. IssueIndex: 1,
  106. PosterID: 5331,
  107. PosterName: "lunny",
  108. PosterEmail: "xiaolunwen@gmail.com",
  109. Created: time.Date(2019, 6, 11, 8, 19, 50, 0, time.UTC),
  110. Updated: time.Date(2019, 6, 11, 8, 19, 50, 0, time.UTC),
  111. Content: "1111",
  112. },
  113. {
  114. IssueIndex: 1,
  115. PosterID: 15822,
  116. PosterName: "clacplouf",
  117. PosterEmail: "test1234@dbn.re",
  118. Created: time.Date(2019, 10, 26, 11, 7, 2, 0, time.UTC),
  119. Updated: time.Date(2019, 10, 26, 11, 7, 2, 0, time.UTC),
  120. Content: "88888888",
  121. },
  122. }, comments)
  123. // downloader.GetPullRequests()
  124. _, _, err = downloader.GetPullRequests(1, 3)
  125. assert.Error(t, err)
  126. }