chore: require.ErrorContains() is intended, but require.Errorf() is used (#11035)

The two commits in this PR fix test cases which did not work as intended, because `require.Errorf()` was used where `require.ErrorContains()` was intended.

The former formats the error output by the test itself when failing, while the latter is to expect the tested error to contain some expected string.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11035
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Nils Goroll <nils.goroll@uplex.de>
Co-committed-by: Nils Goroll <nils.goroll@uplex.de>
This commit is contained in:
Nils Goroll 2026-01-25 19:48:15 +01:00 committed by Gusted
parent 22b5dfdaf1
commit 6412ee12d0
2 changed files with 6 additions and 2 deletions

View file

@ -4,6 +4,7 @@
package git
import (
"fmt"
"path/filepath"
"testing"
"time"
@ -150,7 +151,8 @@ func TestRepository_GetAnnotatedTag(t *testing.T) {
// Annotated tag's name should fail
tag3, err := bareRepo1.GetAnnotatedTag(aTagName)
require.Error(t, err)
require.Errorf(t, err, "Length must be 40: %d", len(aTagName))
require.ErrorContains(t, err,
fmt.Sprintf("length %d has no matched object format: %s", len(aTagName), aTagName))
assert.Nil(t, tag3)
// Lightweight Tag should fail

View file

@ -4,6 +4,7 @@
package setting
import (
"fmt"
"path/filepath"
"testing"
@ -214,5 +215,6 @@ func Test_getIDTokenSettingsForActions(t *testing.T) {
cfg, err = NewConfigProviderFromData(iniStr)
require.NoError(t, err)
err = loadActionsFrom(cfg)
require.Errorf(t, err, "invalid [actions] ID_TOKEN_SIGNING_ALGORITHM %q", Actions.IDTokenSigningAlgorithm)
require.ErrorContains(t, err,
fmt.Sprintf("invalid [actions] ID_TOKEN_SIGNING_ALGORITHM: %q", Actions.IDTokenSigningAlgorithm))
}