mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-01-23 23:38:10 +00:00
72 lines
2.2 KiB
Go
72 lines
2.2 KiB
Go
// SPDX-License-Identifier: MIT
|
|
|
|
package integration
|
|
|
|
import (
|
|
"context"
|
|
"net/url"
|
|
"testing"
|
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
|
"code.gitea.io/gitea/modules/setting"
|
|
"code.gitea.io/gitea/modules/test"
|
|
"code.gitea.io/gitea/services/f3/driver"
|
|
"code.gitea.io/gitea/services/migrations"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
f3_forges "lab.forgefriends.org/friendlyforgeformat/gof3/forges"
|
|
f3_util "lab.forgefriends.org/friendlyforgeformat/gof3/util"
|
|
)
|
|
|
|
func TestF3_CmdMirror_LocalForgejo(t *testing.T) {
|
|
onGiteaRun(t, func(*testing.T, *url.URL) {
|
|
defer test.MockVariable(&setting.F3.Enabled, true)()
|
|
defer test.MockVariable(&setting.Migrations.AllowLocalNetworks, true)()
|
|
// Gitea SDK (go-sdk) need to parse the AppVer from server response, so we must set it to a valid version string.
|
|
defer test.MockVariable(&setting.AppVer, "1.16.0")
|
|
// without migrations.Init() AllowLocalNetworks = true is not effective and
|
|
// a http call fails with "...migration can only call allowed HTTP servers..."
|
|
migrations.Init()
|
|
|
|
ctx := context.Background()
|
|
var userID int64 = 700
|
|
//
|
|
// Step 1: create a fixture as an F3 archive
|
|
//
|
|
userID++
|
|
fixture := f3_forges.NewFixture(t, f3_forges.FixtureF3Factory)
|
|
fixture.NewUser(userID)
|
|
fixture.NewIssue()
|
|
fixture.NewRepository()
|
|
|
|
//
|
|
// Step 3: mirror the F3 archive to the forge
|
|
//
|
|
_, err := cmdForgejoCaptureOutput(t, []string{
|
|
"forgejo", "forgejo-cli", "f3", "mirror",
|
|
"--from-type=f3", "--from", fixture.ForgeRoot.GetDirectory(),
|
|
"--to-type", driver.Name,
|
|
})
|
|
assert.NoError(t, err)
|
|
user, err := user_model.GetUserByName(ctx, fixture.UserFormat.UserName)
|
|
assert.NoError(t, err)
|
|
//
|
|
// Step 4: mirror the forge to an F3 archive
|
|
//
|
|
dumpDir := t.TempDir()
|
|
_, err = cmdForgejoCaptureOutput(t, []string{
|
|
"forgejo", "forgejo-cli", "f3", "mirror",
|
|
"--user", user.Name, "--repository", fixture.ProjectFormat.Name,
|
|
"--from-type", driver.Name,
|
|
"--to-type=f3", "--to", dumpDir,
|
|
})
|
|
assert.NoError(t, err)
|
|
|
|
//
|
|
// Step 5: verify the F3 archive content
|
|
//
|
|
files := f3_util.Command(context.Background(), "find", dumpDir)
|
|
assert.Contains(t, files, "/user/")
|
|
assert.Contains(t, files, "/project/")
|
|
})
|
|
}
|