diff options
author | silverwind <me@silverwind.io> | 2023-07-05 05:41:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-04 23:41:32 -0400 |
commit | 24e64fe37225a315c74c00d1f5e4d024168feea6 (patch) | |
tree | c89664dca5a884d5fc0a322815ce3bc20247cf84 /models/unittest | |
parent | 4e310133f95ba8581c121a32596807721bdd6af9 (diff) | |
download | gitea-24e64fe37225a315c74c00d1f5e4d024168feea6.tar.gz gitea-24e64fe37225a315c74c00d1f5e4d024168feea6.zip |
Replace `interface{}` with `any` (#25686) (#25687)
Same perl replacement as https://github.com/go-gitea/gitea/pull/25686
but for 1.20 to ease future backporting.
Diffstat (limited to 'models/unittest')
-rw-r--r-- | models/unittest/consistency.go | 22 | ||||
-rw-r--r-- | models/unittest/reflection.go | 2 | ||||
-rw-r--r-- | models/unittest/testdb.go | 2 |
3 files changed, 13 insertions, 13 deletions
diff --git a/models/unittest/consistency.go b/models/unittest/consistency.go index 41798c6253..faa02589aa 100644 --- a/models/unittest/consistency.go +++ b/models/unittest/consistency.go @@ -21,10 +21,10 @@ const ( modelsCommentTypeComment = 0 ) -var consistencyCheckMap = make(map[string]func(t assert.TestingT, bean interface{})) +var consistencyCheckMap = make(map[string]func(t assert.TestingT, bean any)) // CheckConsistencyFor test that all matching database entries are consistent -func CheckConsistencyFor(t assert.TestingT, beansToCheck ...interface{}) { +func CheckConsistencyFor(t assert.TestingT, beansToCheck ...any) { for _, bean := range beansToCheck { sliceType := reflect.SliceOf(reflect.TypeOf(bean)) sliceValue := reflect.MakeSlice(sliceType, 0, 10) @@ -42,7 +42,7 @@ func CheckConsistencyFor(t assert.TestingT, beansToCheck ...interface{}) { } } -func checkForConsistency(t assert.TestingT, bean interface{}) { +func checkForConsistency(t assert.TestingT, bean any) { tb, err := db.TableInfo(bean) assert.NoError(t, err) f := consistencyCheckMap[tb.Name] @@ -63,7 +63,7 @@ func init() { return i } - checkForUserConsistency := func(t assert.TestingT, bean interface{}) { + checkForUserConsistency := func(t assert.TestingT, bean any) { user := reflectionWrap(bean) AssertCountByCond(t, "repository", builder.Eq{"owner_id": user.int("ID")}, user.int("NumRepos")) AssertCountByCond(t, "star", builder.Eq{"uid": user.int("ID")}, user.int("NumStars")) @@ -77,7 +77,7 @@ func init() { } } - checkForRepoConsistency := func(t assert.TestingT, bean interface{}) { + checkForRepoConsistency := func(t assert.TestingT, bean any) { repo := reflectionWrap(bean) assert.Equal(t, repo.str("LowerName"), strings.ToLower(repo.str("Name")), "repo: %+v", repo) AssertCountByCond(t, "star", builder.Eq{"repo_id": repo.int("ID")}, repo.int("NumStars")) @@ -113,7 +113,7 @@ func init() { "Unexpected number of closed milestones for repo id: %d", repo.int("ID")) } - checkForIssueConsistency := func(t assert.TestingT, bean interface{}) { + checkForIssueConsistency := func(t assert.TestingT, bean any) { issue := reflectionWrap(bean) typeComment := modelsCommentTypeComment actual := GetCountByCond(t, "comment", builder.Eq{"`type`": typeComment, "issue_id": issue.int("ID")}) @@ -124,14 +124,14 @@ func init() { } } - checkForPullRequestConsistency := func(t assert.TestingT, bean interface{}) { + checkForPullRequestConsistency := func(t assert.TestingT, bean any) { pr := reflectionWrap(bean) issueRow := AssertExistsAndLoadMap(t, "issue", builder.Eq{"id": pr.int("IssueID")}) assert.True(t, parseBool(issueRow["is_pull"])) assert.EqualValues(t, parseInt(issueRow["index"]), pr.int("Index"), "Unexpected index for pull request id: %d", pr.int("ID")) } - checkForMilestoneConsistency := func(t assert.TestingT, bean interface{}) { + checkForMilestoneConsistency := func(t assert.TestingT, bean any) { milestone := reflectionWrap(bean) AssertCountByCond(t, "issue", builder.Eq{"milestone_id": milestone.int("ID")}, milestone.int("NumIssues")) @@ -145,7 +145,7 @@ func init() { assert.Equal(t, completeness, milestone.int("Completeness")) } - checkForLabelConsistency := func(t assert.TestingT, bean interface{}) { + checkForLabelConsistency := func(t assert.TestingT, bean any) { label := reflectionWrap(bean) issueLabels, err := db.GetEngine(db.DefaultContext).Table("issue_label"). Where(builder.Eq{"label_id": label.int("ID")}). @@ -166,13 +166,13 @@ func init() { assert.EqualValues(t, expected, label.int("NumClosedIssues"), "Unexpected number of closed issues for label id: %d", label.int("ID")) } - checkForTeamConsistency := func(t assert.TestingT, bean interface{}) { + checkForTeamConsistency := func(t assert.TestingT, bean any) { team := reflectionWrap(bean) AssertCountByCond(t, "team_user", builder.Eq{"team_id": team.int("ID")}, team.int("NumMembers")) AssertCountByCond(t, "team_repo", builder.Eq{"team_id": team.int("ID")}, team.int("NumRepos")) } - checkForActionConsistency := func(t assert.TestingT, bean interface{}) { + checkForActionConsistency := func(t assert.TestingT, bean any) { action := reflectionWrap(bean) if action.int("RepoID") != 1700 { // dangling intentional repoRow := AssertExistsAndLoadMap(t, "repository", builder.Eq{"id": action.int("RepoID")}) diff --git a/models/unittest/reflection.go b/models/unittest/reflection.go index 1b149b19fe..141fc66b99 100644 --- a/models/unittest/reflection.go +++ b/models/unittest/reflection.go @@ -23,7 +23,7 @@ type reflectionValue struct { v reflect.Value } -func reflectionWrap(v interface{}) *reflectionValue { +func reflectionWrap(v any) *reflectionValue { return &reflectionValue{v: reflect.ValueOf(v)} } diff --git a/models/unittest/testdb.go b/models/unittest/testdb.go index f926a65538..1ff0fdc25b 100644 --- a/models/unittest/testdb.go +++ b/models/unittest/testdb.go @@ -37,7 +37,7 @@ func FixturesDir() string { return fixturesDir } -func fatalTestError(fmtStr string, args ...interface{}) { +func fatalTestError(fmtStr string, args ...any) { _, _ = fmt.Fprintf(os.Stderr, fmtStr, args...) os.Exit(1) } |