選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

gogs_test.go 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. assertRepositoryEqual(t, &base.Repository{
  30. Name: "TESTREPO",
  31. Owner: "lunnytest",
  32. Description: "",
  33. CloneURL: "https://try.gogs.io/lunnytest/TESTREPO.git",
  34. OriginalURL: "https://try.gogs.io/lunnytest/TESTREPO",
  35. DefaultBranch: "master",
  36. }, repo)
  37. milestones, err := downloader.GetMilestones()
  38. assert.NoError(t, err)
  39. assertMilestonesEqual(t, []*base.Milestone{
  40. {
  41. Title: "1.0",
  42. State: "open",
  43. },
  44. }, milestones)
  45. labels, err := downloader.GetLabels()
  46. assert.NoError(t, err)
  47. assertLabelsEqual(t, []*base.Label{
  48. {
  49. Name: "bug",
  50. Color: "ee0701",
  51. },
  52. {
  53. Name: "duplicate",
  54. Color: "cccccc",
  55. },
  56. {
  57. Name: "enhancement",
  58. Color: "84b6eb",
  59. },
  60. {
  61. Name: "help wanted",
  62. Color: "128a0c",
  63. },
  64. {
  65. Name: "invalid",
  66. Color: "e6e6e6",
  67. },
  68. {
  69. Name: "question",
  70. Color: "cc317c",
  71. },
  72. {
  73. Name: "wontfix",
  74. Color: "ffffff",
  75. },
  76. }, labels)
  77. // downloader.GetIssues()
  78. issues, isEnd, err := downloader.GetIssues(1, 8)
  79. assert.NoError(t, err)
  80. assert.False(t, isEnd)
  81. assertIssuesEqual(t, []*base.Issue{
  82. {
  83. Number: 1,
  84. PosterID: 5331,
  85. PosterName: "lunny",
  86. PosterEmail: "xiaolunwen@gmail.com",
  87. Title: "test",
  88. Content: "test",
  89. Milestone: "",
  90. State: "open",
  91. Created: time.Date(2019, 06, 11, 8, 16, 44, 0, time.UTC),
  92. Updated: time.Date(2019, 10, 26, 11, 07, 2, 0, time.UTC),
  93. Labels: []*base.Label{
  94. {
  95. Name: "bug",
  96. Color: "ee0701",
  97. },
  98. },
  99. },
  100. }, issues)
  101. // downloader.GetComments()
  102. comments, _, err := downloader.GetComments(base.GetCommentOptions{
  103. Context: base.BasicIssueContext(1),
  104. })
  105. assert.NoError(t, err)
  106. assertCommentsEqual(t, []*base.Comment{
  107. {
  108. IssueIndex: 1,
  109. PosterID: 5331,
  110. PosterName: "lunny",
  111. PosterEmail: "xiaolunwen@gmail.com",
  112. Created: time.Date(2019, 06, 11, 8, 19, 50, 0, time.UTC),
  113. Updated: time.Date(2019, 06, 11, 8, 19, 50, 0, time.UTC),
  114. Content: "1111",
  115. },
  116. {
  117. IssueIndex: 1,
  118. PosterID: 15822,
  119. PosterName: "clacplouf",
  120. PosterEmail: "test1234@dbn.re",
  121. Created: time.Date(2019, 10, 26, 11, 7, 2, 0, time.UTC),
  122. Updated: time.Date(2019, 10, 26, 11, 7, 2, 0, time.UTC),
  123. Content: "88888888",
  124. },
  125. }, comments)
  126. // downloader.GetPullRequests()
  127. _, _, err = downloader.GetPullRequests(1, 3)
  128. assert.Error(t, err)
  129. }