[F3] tests do not need a running Forgejo server
This commit is contained in:
parent
9eeeab7f8e
commit
b2b9749ac9
2 changed files with 44 additions and 51 deletions
|
@ -5,6 +5,7 @@ package forgejo
|
|||
import (
|
||||
"context"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
|
||||
|
@ -63,6 +64,9 @@ func runMirror(ctx context.Context, c *cli.Context, action cli.ActionFunc) error
|
|||
if err := git.InitSimple(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := models.Init(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return action(c)
|
||||
|
|
|
@ -4,14 +4,11 @@ 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"
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
f3_forges "lab.forgefriends.org/friendlyforgeformat/gof3/forges"
|
||||
|
@ -19,54 +16,46 @@ import (
|
|||
)
|
||||
|
||||
func TestF3_CmdMirror_LocalForgejo(t *testing.T) {
|
||||
onGiteaRun(t, func(*testing.T, *url.URL) {
|
||||
defer test.MockVariableValue(&setting.F3.Enabled, true)()
|
||||
defer test.MockVariableValue(&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.MockVariableValue(&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()
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
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()
|
||||
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/")
|
||||
//
|
||||
// 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/")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue