Skip to content

Commit 2a02734

Browse files
authoredJan 9, 2025··
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
1 parent fa9191b commit 2a02734

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+218
-348
lines changed
 

‎models/asymkey/gpg_key_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
"github.com/keybase/go-crypto/openpgp/packet"
1717
"github.com/stretchr/testify/assert"
18+
"github.com/stretchr/testify/require"
1819
)
1920

2021
func TestCheckArmoredGPGKeyString(t *testing.T) {
@@ -107,9 +108,8 @@ MkM/fdpyc2hY7Dl/+qFmN5MG5yGmMpQcX+RNNR222ibNC1D3wg==
107108
=i9b7
108109
-----END PGP PUBLIC KEY BLOCK-----`
109110
keys, err := checkArmoredGPGKeyString(testGPGArmor)
110-
if !assert.NotEmpty(t, keys) {
111-
return
112-
}
111+
require.NotEmpty(t, keys)
112+
113113
ekey := keys[0]
114114
assert.NoError(t, err, "Could not parse a valid GPG armored key", ekey)
115115

‎models/db/engine_test.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
_ "code.gitea.io/gitea/cmd" // for TestPrimaryKeys
1616

1717
"github.com/stretchr/testify/assert"
18+
"github.com/stretchr/testify/require"
1819
)
1920

2021
func TestDumpDatabase(t *testing.T) {
@@ -62,9 +63,7 @@ func TestPrimaryKeys(t *testing.T) {
6263
// Import "code.gitea.io/gitea/cmd" to make sure each db.RegisterModel in init functions has been called.
6364

6465
beans, err := db.NamesToBean()
65-
if err != nil {
66-
t.Fatal(err)
67-
}
66+
require.NoError(t, err)
6867

6968
whitelist := map[string]string{
7069
"the_table_name_to_skip_checking": "Write a note here to explain why",
@@ -79,8 +78,6 @@ func TestPrimaryKeys(t *testing.T) {
7978
t.Logf("ignore %q because %q", table.Name, why)
8079
continue
8180
}
82-
if len(table.PrimaryKeys) == 0 {
83-
t.Errorf("table %q has no primary key", table.Name)
84-
}
81+
assert.NotEmpty(t, table.PrimaryKeys, "table %q has no primary key", table.Name)
8582
}
8683
}

0 commit comments

Comments
 (0)
Please sign in to comment.