mirror of
https://github.com/go-gitea/gitea.git
synced 2025-06-20 18:03:08 +02:00
Upgrade to [v0.19.0](https://github.com/golang/tools/releases/tag/gopls%2Fv0.19.0) and fix issues. Runs with new `warning` serverity setting. This likely does less checks than before. Additionally, add `make fix` which runs modernize. This is also verified on CI. For the record, here are the issues discoverd when running with `info` severity, in case we want to fix these: ``` tests/integration/repo_test.go:95:5-14: could use tagged switch on i tests/integration/api_packages_generic_test.go:149:4-64: could use tagged switch on setting.Packages.Storage.Type services/webhook/msteams_test.go:33:4-33: could use tagged switch on fact.Name services/webhook/msteams_test.go:59:4-33: could use tagged switch on fact.Name services/webhook/msteams_test.go:85:4-33: could use tagged switch on fact.Name services/webhook/msteams_test.go:111:4-33: could use tagged switch on fact.Name services/webhook/msteams_test.go:138:4-33: could use tagged switch on fact.Name services/webhook/msteams_test.go:161:4-33: could use tagged switch on fact.Name services/webhook/msteams_test.go:187:4-33: could use tagged switch on fact.Name services/webhook/msteams_test.go:213:4-33: could use tagged switch on fact.Name services/webhook/msteams_test.go:239:4-33: could use tagged switch on fact.Name services/webhook/msteams_test.go:266:4-33: could use tagged switch on fact.Name services/webhook/msteams_test.go:407:4-33: could use tagged switch on fact.Name tests/integration/api_packages_conan_test.go:350:6-33: could use tagged switch on pf.Name models/issues/tracked_time_test.go:98:3-18: could use tagged switch on user.ID tests/integration/api_token_test.go:505:5-43: could use tagged switch on minRequiredLevel services/gitdiff/gitdiff.go:220:33-46: method "getLineLegacy" is unused ``` --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package v1_22 //nolint
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"code.gitea.io/gitea/models/migrations/base"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"xorm.io/xorm/schemas"
|
|
)
|
|
|
|
func Test_AddUniqueIndexForProjectIssue(t *testing.T) {
|
|
type ProjectIssue struct { //revive:disable-line:exported
|
|
ID int64 `xorm:"pk autoincr"`
|
|
IssueID int64 `xorm:"INDEX"`
|
|
ProjectID int64 `xorm:"INDEX"`
|
|
}
|
|
|
|
// Prepare and load the testing database
|
|
x, deferable := base.PrepareTestEnv(t, 0, new(ProjectIssue))
|
|
defer deferable()
|
|
if x == nil || t.Failed() {
|
|
return
|
|
}
|
|
|
|
cnt, err := x.Table("project_issue").Where("project_id=1 AND issue_id=1").Count()
|
|
assert.NoError(t, err)
|
|
assert.EqualValues(t, 2, cnt)
|
|
|
|
assert.NoError(t, AddUniqueIndexForProjectIssue(x))
|
|
|
|
cnt, err = x.Table("project_issue").Where("project_id=1 AND issue_id=1").Count()
|
|
assert.NoError(t, err)
|
|
assert.EqualValues(t, 1, cnt)
|
|
|
|
tables, err := x.DBMetas()
|
|
assert.NoError(t, err)
|
|
assert.Len(t, tables, 1)
|
|
found := false
|
|
for _, index := range tables[0].Indexes {
|
|
if index.Type == schemas.UniqueType {
|
|
found = true
|
|
assert.ElementsMatch(t, index.Cols, []string{"project_id", "issue_id"})
|
|
break
|
|
}
|
|
}
|
|
assert.True(t, found)
|
|
}
|