mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-05 01:45:22 +02:00
add port and schema to federation host (#7203)
## Checklist The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org). ### Tests - I added test coverage for Go changes... - [x] in their respective `*_test.go` for unit tests. - [ ] in the `tests/integration` directory if it involves interactions with a live Forgejo server. ### Documentation - [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [ ] I did not document these changes and I do not expect someone else to do it. ### Release notes - [ ] I do not want this change to show in the release notes. - [ ] I want the title to show in the release notes with a link to this pull request. - [ ] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title. Co-authored-by: Michael Jerger <michael.jerger@meissa-gmbh.de> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7203 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: zam <mirco.zachmann@meissa.de> Co-committed-by: zam <mirco.zachmann@meissa.de>
This commit is contained in:
parent
23360ad415
commit
f6a5b783d2
20 changed files with 411 additions and 147 deletions
81
models/forgejo_migrations/v30_test.go
Normal file
81
models/forgejo_migrations/v30_test.go
Normal file
|
@ -0,0 +1,81 @@
|
|||
// Copyright 2025 The Forgejo Authors.
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package forgejo_migrations //nolint:revive
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
migration_tests "forgejo.org/models/migrations/test"
|
||||
"forgejo.org/modules/timeutil"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
func Test_MigrateNormalizedFederatedURI(t *testing.T) {
|
||||
// Old structs
|
||||
type User struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
NormalizedFederatedURI string
|
||||
}
|
||||
type FederatedUser struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
UserID int64 `xorm:"NOT NULL"`
|
||||
ExternalID string `xorm:"UNIQUE(federation_user_mapping) NOT NULL"`
|
||||
FederationHostID int64 `xorm:"UNIQUE(federation_user_mapping) NOT NULL"`
|
||||
}
|
||||
type FederationHost struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
HostFqdn string `xorm:"host_fqdn UNIQUE INDEX VARCHAR(255) NOT NULL"`
|
||||
SoftwareName string `xorm:"NOT NULL"`
|
||||
LatestActivity time.Time `xorm:"NOT NULL"`
|
||||
Created timeutil.TimeStamp `xorm:"created"`
|
||||
Updated timeutil.TimeStamp `xorm:"updated"`
|
||||
}
|
||||
|
||||
// Prepare TestEnv
|
||||
x, deferable := migration_tests.PrepareTestEnv(t, 0,
|
||||
new(User),
|
||||
new(FederatedUser),
|
||||
new(FederationHost),
|
||||
)
|
||||
defer deferable()
|
||||
if x == nil || t.Failed() {
|
||||
return
|
||||
}
|
||||
|
||||
// test for expected results
|
||||
getColumn := func(tn, co string) *schemas.Column {
|
||||
tables, err := x.DBMetas()
|
||||
require.NoError(t, err)
|
||||
var table *schemas.Table
|
||||
for _, elem := range tables {
|
||||
if elem.Name == tn {
|
||||
table = elem
|
||||
break
|
||||
}
|
||||
}
|
||||
return table.GetColumn(co)
|
||||
}
|
||||
|
||||
require.NotNil(t, getColumn("user", "normalized_federated_uri"))
|
||||
require.Nil(t, getColumn("federation_host", "host_port"))
|
||||
require.Nil(t, getColumn("federation_host", "host_schema"))
|
||||
cnt1, err := x.Table("federated_user").Count()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(2), cnt1)
|
||||
|
||||
require.NoError(t, MigrateNormalizedFederatedURI(x))
|
||||
|
||||
require.Nil(t, getColumn("user", "normalized_federated_uri"))
|
||||
require.NotNil(t, getColumn("federation_host", "host_port"))
|
||||
require.NotNil(t, getColumn("federation_host", "host_schema"))
|
||||
cnt2, err := x.Table("federated_user").Count()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(1), cnt2)
|
||||
|
||||
// idempotent
|
||||
require.NoError(t, MigrateNormalizedFederatedURI(x))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue