1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Refactor older tests to use testify (#33140)

Refactor checks to use assert/require
Use require.Eventually for waiting in elastic and meilisearch tests
Use require to exit early instead of assert
This commit is contained in:
TheFox0x7
2025-01-09 02:21:47 +01:00
committed by GitHub
parent fa9191b7b9
commit 2a02734f93
42 changed files with 218 additions and 348 deletions

View File

@@ -5,6 +5,8 @@ package utils
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSanitizeFlashErrorString(t *testing.T) {
@@ -32,9 +34,8 @@ func TestSanitizeFlashErrorString(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := SanitizeFlashErrorString(tt.arg); got != tt.want {
t.Errorf("SanitizeFlashErrorString() = '%v', want '%v'", got, tt.want)
}
got := SanitizeFlashErrorString(tt.arg)
assert.Equal(t, tt.want, got)
})
}
}

View File

@@ -17,6 +17,7 @@ import (
"code.gitea.io/gitea/services/pull"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestRenderConversation(t *testing.T) {
@@ -41,19 +42,16 @@ func TestRenderConversation(t *testing.T) {
var preparedComment *issues_model.Comment
run("prepare", func(t *testing.T, ctx *context.Context, resp *httptest.ResponseRecorder) {
comment, err := pull.CreateCodeComment(ctx, pr.Issue.Poster, ctx.Repo.GitRepo, pr.Issue, 1, "content", "", false, 0, pr.HeadCommitID, nil)
if !assert.NoError(t, err) {
return
}
require.NoError(t, err)
comment.Invalidated = true
err = issues_model.UpdateCommentInvalidate(ctx, comment)
if !assert.NoError(t, err) {
return
}
require.NoError(t, err)
preparedComment = comment
})
if !assert.NotNil(t, preparedComment) {
return
}
require.NotNil(t, preparedComment)
run("diff with outdated", func(t *testing.T, ctx *context.Context, resp *httptest.ResponseRecorder) {
ctx.Data["ShowOutdatedComments"] = true
renderConversation(ctx, preparedComment, "diff")

View File

@@ -20,6 +20,7 @@ import (
wiki_service "code.gitea.io/gitea/services/wiki"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
const (
@@ -66,12 +67,9 @@ func assertWikiNotExists(t *testing.T, repo *repo_model.Repository, wikiName wik
func assertPagesMetas(t *testing.T, expectedNames []string, metas any) {
pageMetas, ok := metas.([]PageMeta)
if !assert.True(t, ok) {
return
}
if !assert.Len(t, pageMetas, len(expectedNames)) {
return
}
require.True(t, ok)
require.Len(t, pageMetas, len(expectedNames))
for i, pageMeta := range pageMetas {
assert.EqualValues(t, expectedNames[i], pageMeta.Name)
}