mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
Fixtures asserted against try.gitea.io, gitea.io and repositories under upstream's accounts. They now use reserved example hosts and an example owner, the recorded downloader responses were renamed to match, and the RPM and Alpine package fixtures were rebuilt with recomputed digests. The schema dumps the migration test restores are named for the version they capture. Two fixtures were wrong, not merely branded. readme-test carried a special-subdir-.gitea branch while the README lookup and its test both read .hanzo, so that case asserted against a branch that did not exist; the branch now holds .hanzo/README.md. The repository fixtures' delegate hooks still re-exec the pre-rename binary name, and the licenses end-to-end test looked for a module this tree no longer depends on. Co-authored-by: Hanzo Dev <[email protected]>
155 lines
4.1 KiB
Go
155 lines
4.1 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package migrations
|
|
|
|
import (
|
|
"net/url"
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/hanzoai/git/models/unittest"
|
|
base "github.com/hanzoai/git/modules/migration"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestOneDevDownloadRepo(t *testing.T) {
|
|
liveMode := os.Getenv("ONEDEV_LIVE") != ""
|
|
|
|
_, callerFile, _, _ := runtime.Caller(0)
|
|
fixtureDir := filepath.Join(filepath.Dir(callerFile), "_mock_data/TestOneDevDownloadRepo")
|
|
mockServer := unittest.NewMockWebServer(t, "https://code.onedev.io", fixtureDir, liveMode)
|
|
|
|
u, _ := url.Parse(mockServer.URL)
|
|
ctx := t.Context()
|
|
downloader := NewOneDevDownloader(ctx, u, "", "", "example-test_repo")
|
|
repo, err := downloader.GetRepoInfo(ctx)
|
|
assert.NoError(t, err)
|
|
assertRepositoryEqual(t, &base.Repository{
|
|
Name: "example-test_repo",
|
|
Owner: "",
|
|
Description: "Test repository for testing migration from OneDev to example",
|
|
CloneURL: mockServer.URL + "/example-test_repo",
|
|
OriginalURL: mockServer.URL + "/example-test_repo",
|
|
}, repo)
|
|
|
|
milestones, err := downloader.GetMilestones(ctx)
|
|
assert.NoError(t, err)
|
|
deadline := time.Unix(1620086400, 0)
|
|
assertMilestonesEqual(t, []*base.Milestone{
|
|
{
|
|
Title: "1.0.0",
|
|
Deadline: &deadline,
|
|
Closed: &deadline,
|
|
State: "closed",
|
|
},
|
|
{
|
|
Title: "1.1.0",
|
|
Description: "next things?",
|
|
State: "open",
|
|
},
|
|
}, milestones)
|
|
|
|
labels, err := downloader.GetLabels(ctx)
|
|
assert.NoError(t, err)
|
|
assert.Len(t, labels, 6)
|
|
|
|
issues, isEnd, err := downloader.GetIssues(ctx, 1, 2)
|
|
assert.NoError(t, err)
|
|
assert.False(t, isEnd)
|
|
assertIssuesEqual(t, []*base.Issue{
|
|
{
|
|
Number: 4,
|
|
Title: "Hi there",
|
|
Content: "an issue not assigned to a milestone",
|
|
PosterName: "User 336",
|
|
State: "open",
|
|
Created: time.Unix(1628549776, 734000000),
|
|
Updated: time.Unix(1628549776, 734000000),
|
|
Labels: []*base.Label{
|
|
{
|
|
Name: "Improvement",
|
|
},
|
|
},
|
|
ForeignIndex: 398,
|
|
Context: onedevIssueContext{IsPullRequest: false},
|
|
},
|
|
{
|
|
Number: 3,
|
|
Title: "Add an awesome feature",
|
|
Content: "just another issue to test against",
|
|
PosterName: "User 336",
|
|
State: "open",
|
|
Milestone: "1.1.0",
|
|
Created: time.Unix(1628549749, 878000000),
|
|
Updated: time.Unix(1628549749, 878000000),
|
|
Labels: []*base.Label{
|
|
{
|
|
Name: "New Feature",
|
|
},
|
|
},
|
|
ForeignIndex: 397,
|
|
Context: onedevIssueContext{IsPullRequest: false},
|
|
},
|
|
}, issues)
|
|
|
|
comments, _, err := downloader.GetComments(ctx, &base.Issue{
|
|
Number: 4,
|
|
ForeignIndex: 398,
|
|
Context: onedevIssueContext{IsPullRequest: false},
|
|
})
|
|
assert.NoError(t, err)
|
|
assertCommentsEqual(t, []*base.Comment{
|
|
{
|
|
IssueIndex: 4,
|
|
PosterID: 336,
|
|
PosterName: "User 336",
|
|
Created: time.Unix(1628549791, 128000000),
|
|
Updated: time.Unix(1628549791, 128000000),
|
|
Content: "it has a comment\n\nEDIT: that got edited",
|
|
},
|
|
}, comments)
|
|
|
|
prs, _, err := downloader.GetPullRequests(ctx, 1, 1)
|
|
assert.NoError(t, err)
|
|
assertPullRequestsEqual(t, []*base.PullRequest{
|
|
{
|
|
Number: 5,
|
|
Title: "Pull to add a new file",
|
|
Content: "just do some git stuff",
|
|
PosterID: 336,
|
|
PosterName: "User 336",
|
|
State: "open",
|
|
Created: time.Unix(1628550076, 25000000),
|
|
Updated: time.Unix(1628550076, 25000000),
|
|
Head: base.PullRequestBranch{
|
|
Ref: "branch-for-a-pull",
|
|
SHA: "343deffe3526b9bc84e873743ff7f6e6d8b827c0",
|
|
RepoName: "example-test_repo",
|
|
},
|
|
Base: base.PullRequestBranch{
|
|
Ref: "master",
|
|
SHA: "f32b0a9dfd09a60f616f29158f772cedd89942d2",
|
|
RepoName: "example-test_repo",
|
|
},
|
|
ForeignIndex: 186,
|
|
Context: onedevIssueContext{IsPullRequest: true},
|
|
},
|
|
}, prs)
|
|
|
|
rvs, err := downloader.GetReviews(ctx, &base.PullRequest{Number: 5, ForeignIndex: 186})
|
|
assert.NoError(t, err)
|
|
assertReviewsEqual(t, []*base.Review{
|
|
{
|
|
IssueIndex: 5,
|
|
ReviewerID: 317,
|
|
ReviewerName: "User 317",
|
|
State: "PENDING",
|
|
},
|
|
}, rvs)
|
|
}
|