forgejo/models/forgejo/semver/semver_test.go
Earl Warren fdfbda0f9b
[SEMVER] store SemVer in ForgejoSemVer after a database upgrade
(cherry picked from commit b7fe7cf401)
(cherry picked from commit cf339eed4f)
(cherry picked from commit 4f3a16168b)
(cherry picked from commit 6f5bbc53fc)
(cherry picked from commit aca42b422e)
(cherry picked from commit 5a7f7580e5)
(cherry picked from commit 06c383c807)
(cherry picked from commit fe831dcb53)
(cherry picked from commit cd12cd0dbc)
(cherry picked from commit cc79163703)
(cherry picked from commit f3ad9d345f)
(cherry picked from commit 1a01baaa0f)
(cherry picked from commit 21123afcfd)
2023-10-30 13:54:48 +01:00

46 lines
1.1 KiB
Go

// SPDX-License-Identifier: MIT
package semver
import (
"testing"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest"
"github.com/hashicorp/go-version"
"github.com/stretchr/testify/assert"
)
func TestForgejoSemVerSetGet(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
ctx := db.DefaultContext
newVersion, err := version.NewVersion("v1.2.3")
assert.NoError(t, err)
assert.NoError(t, SetVersionString(ctx, newVersion.String()))
databaseVersion, err := GetVersion(ctx)
assert.NoError(t, err)
assert.EqualValues(t, newVersion.String(), databaseVersion.String())
assert.True(t, newVersion.Equal(databaseVersion))
}
func TestForgejoSemVerMissing(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
ctx := db.DefaultContext
e := db.GetEngine(ctx)
_, err := e.Exec("delete from forgejo_sem_ver")
assert.NoError(t, err)
v, err := GetVersion(ctx)
assert.NoError(t, err)
assert.EqualValues(t, "1.0.0", v.String())
_, err = e.Exec("drop table forgejo_sem_ver")
assert.NoError(t, err)
v, err = GetVersion(ctx)
assert.NoError(t, err)
assert.EqualValues(t, "1.0.0", v.String())
}