code.gitea.io/gitea@v1.21.7/services/migrations/onedev_test.go (about)

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