[F3] driver compliance tests

This commit is contained in:
Earl Warren 2024-02-03 09:24:21 +01:00
parent f29888d8db
commit 2a56eecf69
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
18 changed files with 338 additions and 9 deletions

2
go.mod
View file

@ -117,7 +117,7 @@ require (
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
gopkg.in/ini.v1 v1.67.0 gopkg.in/ini.v1 v1.67.0
gopkg.in/yaml.v3 v3.0.1 gopkg.in/yaml.v3 v3.0.1
lab.forgefriends.org/friendlyforgeformat/gof3 v1.0.1-0.20240126111813-4c40a08fea9f lab.forgefriends.org/friendlyforgeformat/gof3 v1.0.1-0.20240203081417-c4d660889147
mvdan.cc/xurls/v2 v2.5.0 mvdan.cc/xurls/v2 v2.5.0
strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251 strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251
xorm.io/builder v0.3.13 xorm.io/builder v0.3.13

4
go.sum
View file

@ -1287,8 +1287,8 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
lab.forgefriends.org/friendlyforgeformat/gof3 v1.0.1-0.20240126111813-4c40a08fea9f h1:+Q6wWzybQgshhH6VzdjdpvsF/iJRvVk0YCyEgdZiJIQ= lab.forgefriends.org/friendlyforgeformat/gof3 v1.0.1-0.20240203081417-c4d660889147 h1:V2+nx8FB1tGWBlgyQ97keJCYrVVmVDu5zw9OoSZxXRI=
lab.forgefriends.org/friendlyforgeformat/gof3 v1.0.1-0.20240126111813-4c40a08fea9f/go.mod h1:LxfG8cikPNzmy77CCYM4b9t/NbFefGJ1rUZujqDNa8Y= lab.forgefriends.org/friendlyforgeformat/gof3 v1.0.1-0.20240203081417-c4d660889147/go.mod h1:LxfG8cikPNzmy77CCYM4b9t/NbFefGJ1rUZujqDNa8Y=
lukechampine.com/uint128 v1.2.0 h1:mBi/5l91vocEN8otkC5bDLhi2KdCticRiwbdB0O+rjI= lukechampine.com/uint128 v1.2.0 h1:mBi/5l91vocEN8otkC5bDLhi2KdCticRiwbdB0O+rjI=
lukechampine.com/uint128 v1.2.0/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk= lukechampine.com/uint128 v1.2.0/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
modernc.org/cc/v3 v3.40.0 h1:P3g79IUS/93SYhtoeaHW+kRCIrYaxJ27MFPv+7kaTOw= modernc.org/cc/v3 v3.40.0 h1:P3g79IUS/93SYhtoeaHW+kRCIrYaxJ27MFPv+7kaTOw=

View file

@ -0,0 +1,29 @@
// Copyright Earl Warren <contact@earl-warren.org>
// Copyright Loïc Dachary <loic@dachary.org>
// SPDX-License-Identifier: MIT
package driver
import (
"context"
"lab.forgefriends.org/friendlyforgeformat/gof3/tree/generic"
)
type common struct {
generic.NullDriver
}
func (o *common) GetHelper() any {
panic("not implemented")
}
func (o *common) ListPage(ctx context.Context, page int) generic.ChildrenSlice {
return generic.NewChildrenSlice(0)
}
func (o *common) getKind() generic.Kind {
return o.GetNode().GetKind()
}
func (o *common) IsNull() bool { return false }

View file

@ -0,0 +1,43 @@
// Copyright Earl Warren <contact@earl-warren.org>
// Copyright Loïc Dachary <loic@dachary.org>
// SPDX-License-Identifier: MIT
package driver
import (
"context"
"lab.forgefriends.org/friendlyforgeformat/gof3/f3"
f3_tree "lab.forgefriends.org/friendlyforgeformat/gof3/tree/f3"
"lab.forgefriends.org/friendlyforgeformat/gof3/tree/generic"
)
type container struct {
common
}
func (o *container) NewFormat() f3.Interface {
node := o.GetNode()
return node.GetTree().(f3_tree.TreeInterface).NewFormat(node.GetKind())
}
func (o *container) ToFormat() f3.Interface {
return o.NewFormat()
}
func (o *container) FromFormat(content f3.Interface) {
}
func (o *container) Get(context.Context) bool { return true }
func (o *container) Put(ctx context.Context) generic.NodeID {
return o.upsert(ctx)
}
func (o *container) Patch(ctx context.Context) {
o.upsert(ctx)
}
func (o *container) upsert(context.Context) generic.NodeID {
return generic.NodeID(o.getKind())
}

View file

@ -0,0 +1,35 @@
// Copyright Earl Warren <contact@earl-warren.org>
// Copyright Loïc Dachary <loic@dachary.org>
// SPDX-License-Identifier: MIT
package driver
import (
"context"
"lab.forgefriends.org/friendlyforgeformat/gof3/f3"
"lab.forgefriends.org/friendlyforgeformat/gof3/tree/generic"
)
type forge struct {
generic.NullDriver
}
func newForge() generic.NodeDriverInterface {
return &forge{}
}
func (o *forge) Equals(context.Context, generic.NodeInterface) bool { return true }
func (o *forge) Get(context.Context) bool { return true }
func (o *forge) Put(context.Context) generic.NodeID { return generic.NodeID("forge") }
func (o *forge) Patch(context.Context) {}
func (o *forge) Delete(context.Context) {}
func (o *forge) NewFormat() f3.Interface { return &f3.Forge{} }
func (o *forge) FromFormat(f3.Interface) {}
func (o *forge) ToFormat() f3.Interface {
return &f3.Forge{
Common: f3.NewCommon("forge"),
URL: o.String(),
}
}

View file

@ -5,11 +5,13 @@
package driver package driver
import ( import (
driver_options "code.gitea.io/gitea/services/f3/driver/options"
"lab.forgefriends.org/friendlyforgeformat/gof3/options" "lab.forgefriends.org/friendlyforgeformat/gof3/options"
f3_tree "lab.forgefriends.org/friendlyforgeformat/gof3/tree/f3" f3_tree "lab.forgefriends.org/friendlyforgeformat/gof3/tree/f3"
) )
func init() { func init() {
f3_tree.RegisterForgeFactory(Name, newTreeDriver) f3_tree.RegisterForgeFactory(driver_options.Name, newTreeDriver)
options.RegisterFactory(Name, newOptions) options.RegisterFactory(driver_options.Name, newOptions)
} }

View file

@ -8,17 +8,21 @@ import (
"testing" "testing"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
driver_options "code.gitea.io/gitea/services/f3/driver/options"
_ "code.gitea.io/gitea/models" _ "code.gitea.io/gitea/models"
_ "code.gitea.io/gitea/models/actions" _ "code.gitea.io/gitea/models/actions"
_ "code.gitea.io/gitea/models/activities" _ "code.gitea.io/gitea/models/activities"
_ "code.gitea.io/gitea/models/perm/access" _ "code.gitea.io/gitea/models/perm/access"
_ "code.gitea.io/gitea/services/f3/driver/tests"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
tests_f3 "lab.forgefriends.org/friendlyforgeformat/gof3/tree/tests/f3"
) )
func TestF3(t *testing.T) { func TestF3(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase()) assert.NoError(t, unittest.PrepareTestDatabase())
tests_f3.ForgeCompliance(t, driver_options.Name)
} }
func TestMain(m *testing.M) { func TestMain(m *testing.M) {

View file

@ -7,14 +7,14 @@ package driver
import ( import (
"net/http" "net/http"
forgejo_options "code.gitea.io/gitea/services/f3/driver/options" driver_options "code.gitea.io/gitea/services/f3/driver/options"
"lab.forgefriends.org/friendlyforgeformat/gof3/options" "lab.forgefriends.org/friendlyforgeformat/gof3/options"
) )
func newOptions() options.Interface { func newOptions() options.Interface {
o := &forgejo_options.Options{} o := &driver_options.Options{}
o.SetName(Name) o.SetName(driver_options.Name)
o.SetNewMigrationHTTPClient(func() *http.Client { return &http.Client{} }) o.SetNewMigrationHTTPClient(func() *http.Client { return &http.Client{} })
return o return o
} }

View file

@ -2,6 +2,6 @@
// Copyright Loïc Dachary <loic@dachary.org> // Copyright Loïc Dachary <loic@dachary.org>
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
package driver package options
const Name = "internal_forgejo" const Name = "internal_forgejo"

View file

@ -0,0 +1,17 @@
// Copyright Earl Warren <contact@earl-warren.org>
// Copyright Loïc Dachary <loic@dachary.org>
// SPDX-License-Identifier: MIT
package driver
import (
"lab.forgefriends.org/friendlyforgeformat/gof3/tree/generic"
)
type organizations struct {
container
}
func newOrganizations() generic.NodeDriverInterface {
return &organizations{}
}

View file

@ -0,0 +1,17 @@
// Copyright Earl Warren <contact@earl-warren.org>
// Copyright Loïc Dachary <loic@dachary.org>
// SPDX-License-Identifier: MIT
package driver
import (
"lab.forgefriends.org/friendlyforgeformat/gof3/tree/generic"
)
type projects struct {
container
}
func newProjects() generic.NodeDriverInterface {
return &projects{}
}

View file

@ -0,0 +1,41 @@
// Copyright Earl Warren <contact@earl-warren.org>
// Copyright Loïc Dachary <loic@dachary.org>
// SPDX-License-Identifier: MIT
package driver
import (
"context"
"lab.forgefriends.org/friendlyforgeformat/gof3/f3"
"lab.forgefriends.org/friendlyforgeformat/gof3/tree/generic"
)
type root struct {
generic.NullDriver
content f3.Interface
}
func newRoot(content f3.Interface) generic.NodeDriverInterface {
return &root{
content: content,
}
}
func (o *root) FromFormat(content f3.Interface) {
o.content = content
}
func (o *root) ToFormat() f3.Interface {
return o.content
}
func (o *root) Get(context.Context) bool { return true }
func (o *root) Put(context.Context) generic.NodeID {
return generic.NilID
}
func (o *root) Patch(context.Context) {
}

View file

@ -0,0 +1,15 @@
// Copyright Earl Warren <contact@earl-warren.org>
// Copyright Loïc Dachary <loic@dachary.org>
// SPDX-License-Identifier: MIT
package tests
import (
driver_options "code.gitea.io/gitea/services/f3/driver/options"
tests_forge "lab.forgefriends.org/friendlyforgeformat/gof3/tree/tests/f3/forge"
)
func init() {
tests_forge.RegisterFactory(driver_options.Name, newForgeTest)
}

View file

@ -0,0 +1,50 @@
// Copyright Earl Warren <contact@earl-warren.org>
// Copyright Loïc Dachary <loic@dachary.org>
// SPDX-License-Identifier: MIT
package tests
import (
"testing"
driver_options "code.gitea.io/gitea/services/f3/driver/options"
"lab.forgefriends.org/friendlyforgeformat/gof3/options"
f3_tree "lab.forgefriends.org/friendlyforgeformat/gof3/tree/f3"
"lab.forgefriends.org/friendlyforgeformat/gof3/tree/generic"
forge_test "lab.forgefriends.org/friendlyforgeformat/gof3/tree/tests/f3/forge"
)
type forgeTest struct {
forge_test.Base
}
func (o *forgeTest) NewOptions(t *testing.T) options.Interface {
return newTestOptions(t)
}
func (o *forgeTest) GetExceptions() []generic.Kind {
return []generic.Kind{
f3_tree.KindAssets,
f3_tree.KindComments,
f3_tree.KindIssues,
f3_tree.KindLabels,
f3_tree.KindMilestones,
f3_tree.KindOrganizations,
f3_tree.KindProjects,
f3_tree.KindPullRequests,
f3_tree.KindReactions,
f3_tree.KindReleases,
f3_tree.KindRepositories,
f3_tree.KindReviews,
f3_tree.KindReviewComments,
f3_tree.KindTopics,
f3_tree.KindUsers,
}
}
func newForgeTest() forge_test.Interface {
t := &forgeTest{}
t.SetName(driver_options.Name)
return t
}

View file

@ -0,0 +1,21 @@
// Copyright Earl Warren <contact@earl-warren.org>
// Copyright Loïc Dachary <loic@dachary.org>
// SPDX-License-Identifier: MIT
package tests
import (
"testing"
forgejo_log "code.gitea.io/gitea/modules/log"
driver_options "code.gitea.io/gitea/services/f3/driver/options"
"code.gitea.io/gitea/services/f3/util"
"lab.forgefriends.org/friendlyforgeformat/gof3/options"
)
func newTestOptions(t *testing.T) options.Interface {
o := options.GetFactory(driver_options.Name)().(*driver_options.Options)
o.SetLogger(util.NewF3Logger(nil, forgejo_log.GetLogger(forgejo_log.DEFAULT)))
return o
}

View file

@ -0,0 +1,17 @@
// Copyright Earl Warren <contact@earl-warren.org>
// Copyright Loïc Dachary <loic@dachary.org>
// SPDX-License-Identifier: MIT
package driver
import (
"lab.forgefriends.org/friendlyforgeformat/gof3/tree/generic"
)
type topics struct {
container
}
func newTopics() generic.NodeDriverInterface {
return &topics{}
}

View file

@ -5,8 +5,12 @@
package driver package driver
import ( import (
"context"
"fmt"
forgejo_options "code.gitea.io/gitea/services/f3/driver/options" forgejo_options "code.gitea.io/gitea/services/f3/driver/options"
f3_tree "lab.forgefriends.org/friendlyforgeformat/gof3/tree/f3"
"lab.forgefriends.org/friendlyforgeformat/gof3/tree/generic" "lab.forgefriends.org/friendlyforgeformat/gof3/tree/generic"
) )
@ -20,6 +24,23 @@ func (o *treeDriver) Init() {
o.NullTreeDriver.Init() o.NullTreeDriver.Init()
} }
func (o *treeDriver) Factory(ctx context.Context, kind generic.Kind) generic.NodeDriverInterface {
switch kind {
case f3_tree.KindUsers:
return newUsers()
case f3_tree.KindOrganizations:
return newOrganizations()
case f3_tree.KindTopics:
return newTopics()
case f3_tree.KindForge:
return newForge()
case generic.KindRoot:
return newRoot(o.GetTree().(f3_tree.TreeInterface).NewFormat(kind))
default:
panic(fmt.Errorf("unexpected kind %s", kind))
}
}
func newTreeDriver(tree generic.TreeInterface, anyOptions any) generic.TreeDriverInterface { func newTreeDriver(tree generic.TreeInterface, anyOptions any) generic.TreeDriverInterface {
driver := &treeDriver{ driver := &treeDriver{
options: anyOptions.(*forgejo_options.Options), options: anyOptions.(*forgejo_options.Options),

View file

@ -0,0 +1,17 @@
// Copyright Earl Warren <contact@earl-warren.org>
// Copyright Loïc Dachary <loic@dachary.org>
// SPDX-License-Identifier: MIT
package driver
import (
"lab.forgefriends.org/friendlyforgeformat/gof3/tree/generic"
)
type users struct {
container
}
func newUsers() generic.NodeDriverInterface {
return &users{}
}