[F3] tests do not need a running Forgejo server

This commit is contained in:
Earl Warren 2023-09-14 10:59:54 +02:00
parent 9eeeab7f8e
commit b2b9749ac9
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
2 changed files with 44 additions and 51 deletions

View file

@ -5,6 +5,7 @@ package forgejo
import ( import (
"context" "context"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log" "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 { if err := git.InitSimple(ctx); err != nil {
return err return err
} }
if err := models.Init(ctx); err != nil {
return err
}
} }
return action(c) return action(c)

View file

@ -4,14 +4,11 @@ package integration
import ( import (
"context" "context"
"net/url"
"testing" "testing"
user_model "code.gitea.io/gitea/models/user" 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/f3/driver"
"code.gitea.io/gitea/services/migrations" "code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
f3_forges "lab.forgefriends.org/friendlyforgeformat/gof3/forges" f3_forges "lab.forgefriends.org/friendlyforgeformat/gof3/forges"
@ -19,14 +16,7 @@ import (
) )
func TestF3_CmdMirror_LocalForgejo(t *testing.T) { func TestF3_CmdMirror_LocalForgejo(t *testing.T) {
onGiteaRun(t, func(*testing.T, *url.URL) { defer tests.PrepareTestEnv(t)()
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()
ctx := context.Background() ctx := context.Background()
var userID int64 = 700 var userID int64 = 700
@ -68,5 +58,4 @@ func TestF3_CmdMirror_LocalForgejo(t *testing.T) {
files := f3_util.Command(context.Background(), "find", dumpDir) files := f3_util.Command(context.Background(), "find", dumpDir)
assert.Contains(t, files, "/user/") assert.Contains(t, files, "/user/")
assert.Contains(t, files, "/project/") assert.Contains(t, files, "/project/")
})
} }