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.

onedev_test.go 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // Copyright 2021 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package migrations
  4. import (
  5. "context"
  6. "net/http"
  7. "net/url"
  8. "testing"
  9. "time"
  10. base "code.gitea.io/gitea/modules/migration"
  11. "github.com/stretchr/testify/assert"
  12. )
  13. func TestOneDevDownloadRepo(t *testing.T) {
  14. resp, err := http.Get("https://code.onedev.io/projects/go-gitea-test_repo")
  15. if err != nil || resp.StatusCode != http.StatusOK {
  16. t.Skipf("Can't access test repo, skipping %s", t.Name())
  17. }
  18. u, _ := url.Parse("https://code.onedev.io")
  19. downloader := NewOneDevDownloader(context.Background(), u, "", "", "go-gitea-test_repo")
  20. if err != nil {
  21. t.Fatalf("NewOneDevDownloader is nil: %v", err)
  22. }
  23. repo, err := downloader.GetRepoInfo()
  24. assert.NoError(t, err)
  25. assertRepositoryEqual(t, &base.Repository{
  26. Name: "go-gitea-test_repo",
  27. Owner: "",
  28. Description: "Test repository for testing migration from OneDev to gitea",
  29. CloneURL: "https://code.onedev.io/go-gitea-test_repo",
  30. OriginalURL: "https://code.onedev.io/projects/go-gitea-test_repo",
  31. }, repo)
  32. milestones, err := downloader.GetMilestones()
  33. assert.NoError(t, err)
  34. deadline := time.Unix(1620086400, 0)
  35. assertMilestonesEqual(t, []*base.Milestone{
  36. {
  37. Title: "1.0.0",
  38. Deadline: &deadline,
  39. Closed: &deadline,
  40. },
  41. {
  42. Title: "1.1.0",
  43. Description: "next things?",
  44. },
  45. }, milestones)
  46. labels, err := downloader.GetLabels()
  47. assert.NoError(t, err)
  48. assert.Len(t, labels, 6)
  49. issues, isEnd, err := downloader.GetIssues(1, 2)
  50. assert.NoError(t, err)
  51. assert.False(t, isEnd)
  52. assertIssuesEqual(t, []*base.Issue{
  53. {
  54. Number: 4,
  55. Title: "Hi there",
  56. Content: "an issue not assigned to a milestone",
  57. PosterName: "User 336",
  58. State: "open",
  59. Created: time.Unix(1628549776, 734000000),
  60. Updated: time.Unix(1628549776, 734000000),
  61. Labels: []*base.Label{
  62. {
  63. Name: "Improvement",
  64. },
  65. },
  66. ForeignIndex: 398,
  67. Context: onedevIssueContext{IsPullRequest: false},
  68. },
  69. {
  70. Number: 3,
  71. Title: "Add an awesome feature",
  72. Content: "just another issue to test against",
  73. PosterName: "User 336",
  74. State: "open",
  75. Milestone: "1.1.0",
  76. Created: time.Unix(1628549749, 878000000),
  77. Updated: time.Unix(1628549749, 878000000),
  78. Labels: []*base.Label{
  79. {
  80. Name: "New Feature",
  81. },
  82. },
  83. ForeignIndex: 397,
  84. Context: onedevIssueContext{IsPullRequest: false},
  85. },
  86. }, issues)
  87. comments, _, err := downloader.GetComments(&base.Issue{
  88. Number: 4,
  89. ForeignIndex: 398,
  90. Context: onedevIssueContext{IsPullRequest: false},
  91. })
  92. assert.NoError(t, err)
  93. assertCommentsEqual(t, []*base.Comment{
  94. {
  95. IssueIndex: 4,
  96. PosterName: "User 336",
  97. Created: time.Unix(1628549791, 128000000),
  98. Updated: time.Unix(1628549791, 128000000),
  99. Content: "it has a comment\n\nEDIT: that got edited",
  100. },
  101. }, comments)
  102. prs, _, err := downloader.GetPullRequests(1, 1)
  103. assert.NoError(t, err)
  104. assertPullRequestsEqual(t, []*base.PullRequest{
  105. {
  106. Number: 5,
  107. Title: "Pull to add a new file",
  108. Content: "just do some git stuff",
  109. PosterName: "User 336",
  110. State: "open",
  111. Created: time.Unix(1628550076, 25000000),
  112. Updated: time.Unix(1628550076, 25000000),
  113. Head: base.PullRequestBranch{
  114. Ref: "branch-for-a-pull",
  115. SHA: "343deffe3526b9bc84e873743ff7f6e6d8b827c0",
  116. RepoName: "go-gitea-test_repo",
  117. },
  118. Base: base.PullRequestBranch{
  119. Ref: "master",
  120. SHA: "f32b0a9dfd09a60f616f29158f772cedd89942d2",
  121. RepoName: "go-gitea-test_repo",
  122. },
  123. ForeignIndex: 186,
  124. Context: onedevIssueContext{IsPullRequest: true},
  125. },
  126. }, prs)
  127. rvs, err := downloader.GetReviews(&base.PullRequest{Number: 5, ForeignIndex: 186})
  128. assert.NoError(t, err)
  129. assertReviewsEqual(t, []*base.Review{
  130. {
  131. IssueIndex: 5,
  132. ReviewerName: "User 317",
  133. State: "PENDING",
  134. },
  135. }, rvs)
  136. }