mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-24 18:10:52 +00:00
fix: ensure consistent empty repository topics field (#7920)
Resolves #7878 An empty repository topic was not stored consistently across databases, this caused the `ONLY_SHOW_RELEVANT_REPOS` feature to not work correctly. Always store empty repository topics as an empty array to fix this. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7920 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: Maks1mS <maks1ms@noreply.codeberg.org> Co-committed-by: Maks1mS <maks1ms@noreply.codeberg.org>
This commit is contained in:
parent
d6ab2a464f
commit
8e2747859b
10 changed files with 163 additions and 2 deletions
38
models/forgejo_migrations/v31_test.go
Normal file
38
models/forgejo_migrations/v31_test.go
Normal file
|
@ -0,0 +1,38 @@
|
|||
// Copyright 2025 The Forgejo Authors.
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package forgejo_migrations //nolint:revive
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
migration_tests "forgejo.org/models/migrations/test"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_SetTopicsAsEmptySlice(t *testing.T) {
|
||||
type Repository struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
Topics []string `xorm:"TEXT JSON"`
|
||||
}
|
||||
|
||||
x, deferable := migration_tests.PrepareTestEnv(t, 0, new(Repository))
|
||||
defer deferable()
|
||||
if x == nil || t.Failed() {
|
||||
return
|
||||
}
|
||||
|
||||
require.NoError(t, SetTopicsAsEmptySlice(x))
|
||||
|
||||
var repos []Repository
|
||||
require.NoError(t, x.Find(&repos))
|
||||
|
||||
for _, repo := range repos {
|
||||
if repo.ID == 2 {
|
||||
require.Equal(t, []string{"go", "dev"}, repo.Topics, "Valid topics should remain unchanged")
|
||||
} else {
|
||||
require.Equal(t, []string{}, repo.Topics, "NULL topics should be set to empty array")
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue