mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-07-25 10:57:37 +00:00
Upgrade Forgejo to our forked [xorm v1.4.0](https://code.forgejo.org/xorm/xorm/compare/v1.3.9-forgejo.12...v1.4.0), which is now named `code.forgejo.org/xorm/xorm` to reflect the current expectation that it is a permanent fork. A small number of API changes were made recently in https://code.forgejo.org/xorm/xorm/issues/120 which are accounted for in this PR, in addition to the module rename. ## Checklist The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. All work and communication must conform to Forgejo's [AI Agreement](https://codeberg.org/forgejo/governance/src/branch/main/AIAgreement.md). 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). ### Documentation - [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [x] I did not document these changes and I do not expect someone else to do it. ### Release notes - [ ] This change will be noticed by a Forgejo user or admin (feature, bug fix, performance, etc.). I suggest to include a release note for this change. - [x] This change is not visible to a Forgejo user or admin (refactor, dependency upgrade, etc.). I think there is no need to add a release note for this change. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/12639 Reviewed-by: Otto <otto@codeberg.org>
64 lines
1.8 KiB
Go
64 lines
1.8 KiB
Go
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package gitea_migrations
|
|
|
|
import (
|
|
"testing"
|
|
|
|
migration_tests "forgejo.org/models/gitea_migrations/test"
|
|
"forgejo.org/modules/test"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestMigrations(t *testing.T) {
|
|
defer test.MockVariableValue(&preparedMigrations, []*migration{
|
|
{idNumber: 70},
|
|
{idNumber: 71},
|
|
})()
|
|
assert.EqualValues(t, 72, calcDBVersion(preparedMigrations))
|
|
assert.EqualValues(t, 72, ExpectedDBVersion())
|
|
|
|
assert.EqualValues(t, 71, migrationIDNumberToDBVersion(70))
|
|
|
|
assert.Equal(t, []*migration{{idNumber: 70}, {idNumber: 71}}, getPendingMigrations(70, preparedMigrations))
|
|
assert.Equal(t, []*migration{{idNumber: 71}}, getPendingMigrations(71, preparedMigrations))
|
|
assert.Equal(t, []*migration{}, getPendingMigrations(72, preparedMigrations))
|
|
}
|
|
|
|
func TestMigrateFreshDB(t *testing.T) {
|
|
x, deferable := migration_tests.PrepareTestEnv(t, 0, new(Version))
|
|
defer deferable()
|
|
require.NotNil(t, x)
|
|
|
|
err := Migrate(x)
|
|
require.NoError(t, err)
|
|
|
|
var versionRecords []*Version
|
|
err = x.Find(&versionRecords)
|
|
require.NoError(t, err)
|
|
require.Len(t, versionRecords, 1)
|
|
v := versionRecords[0]
|
|
assert.EqualValues(t, 1, v.ID)
|
|
assert.EqualValues(t, 305, v.Version)
|
|
}
|
|
|
|
func TestMigrateFailWithCorruption(t *testing.T) {
|
|
x, deferable := migration_tests.PrepareTestEnv(t, 0, new(Version))
|
|
defer deferable()
|
|
require.NotNil(t, x)
|
|
|
|
// ID != 1
|
|
_, err := x.Insert(&Version{ID: 100, Version: 100})
|
|
require.NoError(t, err)
|
|
err = Migrate(x)
|
|
require.ErrorContains(t, err, "corrupted records in the table `version`")
|
|
|
|
// Two versions...
|
|
_, err = x.Insert(&Version{ID: 1, Version: 1000})
|
|
require.NoError(t, err)
|
|
err = Migrate(x)
|
|
require.ErrorContains(t, err, "unexpected records in the table `version`")
|
|
}
|