forked from forgejo/forgejo
[F3] move f3 under forgejo-cli
* simplify the tests by re-using the forgejo-cli helpers to capture the output * unify CmdF3 to be structured in the same way CmdActions is
This commit is contained in:
parent
6f571fba30
commit
4c9fe58b74
6 changed files with 150 additions and 187 deletions
75
tests/integration/cmd_forgejo_f3_test.go
Normal file
75
tests/integration/cmd_forgejo_f3_test.go
Normal file
|
@ -0,0 +1,75 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package integration
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
"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 Test_CmdF3(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()
|
||||
|
||||
//
|
||||
// Step 1: create a fixture
|
||||
//
|
||||
fixture := f3_forges.NewFixture(t, f3_forges.FixtureF3Factory)
|
||||
fixture.NewUser(1234)
|
||||
fixture.NewMilestone()
|
||||
fixture.NewLabel()
|
||||
fixture.NewIssue()
|
||||
fixture.NewTopic()
|
||||
fixture.NewRepository()
|
||||
fixture.NewRelease()
|
||||
fixture.NewAsset()
|
||||
fixture.NewIssueComment(nil)
|
||||
fixture.NewIssueReaction()
|
||||
|
||||
//
|
||||
// Step 2: import the fixture into Gitea
|
||||
//
|
||||
{
|
||||
output, err := cmdForgejoCaptureOutput(t, []string{"forgejo", "forgejo-cli", "f3", "--import", "--directory", fixture.ForgeRoot.GetDirectory()})
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, "imported\n", output)
|
||||
}
|
||||
|
||||
//
|
||||
// Step 3: export Gitea into F3
|
||||
//
|
||||
directory := t.TempDir()
|
||||
{
|
||||
output, err := cmdForgejoCaptureOutput(t, []string{"forgejo", "forgejo-cli", "f3", "--export", "--no-pull-request", "--user", fixture.UserFormat.UserName, "--repository", fixture.ProjectFormat.Name, "--directory", directory})
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, "exported\n", output)
|
||||
}
|
||||
|
||||
//
|
||||
// Step 4: verify the export and import are equivalent
|
||||
//
|
||||
files := f3_util.Command(context.Background(), "find", directory)
|
||||
assert.Contains(t, files, "/label/")
|
||||
assert.Contains(t, files, "/issue/")
|
||||
assert.Contains(t, files, "/milestone/")
|
||||
assert.Contains(t, files, "/topic/")
|
||||
assert.Contains(t, files, "/release/")
|
||||
assert.Contains(t, files, "/asset/")
|
||||
assert.Contains(t, files, "/reaction/")
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue