Skip to content

Commit 3d7d750

Browse files
KN4CK3Rzeripathtechknowlogick
authored
Fix individual tests (addition to #15802) (#15818)
* Decouple TestAction_GetRepoLink and TestSizedAvatarLink. * Load database for TestCheckGPGUserEmail. * Load database for TestMakeIDsFromAPIAssigneesToAdd. * Load database for TestGetUserIDsByNames and TestGetMaileableUsersByIDs. * Load database for TestUser_ToUser. * Load database for TestRepository_EditWikiPage. * Include AppSubURL in test. * Prevent panic with empty slice. Co-authored-by: zeripath <[email protected]> Co-authored-by: techknowlogick <[email protected]>
1 parent 96b1315 commit 3d7d750

File tree

6 files changed

+33
-7
lines changed

6 files changed

+33
-7
lines changed

models/avatar_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ func TestHashEmail(t *testing.T) {
4040
}
4141

4242
func TestSizedAvatarLink(t *testing.T) {
43+
setting.AppSubURL = "/testsuburl"
44+
4345
disableGravatar()
44-
assert.Equal(t, "/suburl/assets/img/avatar_default.png",
46+
assert.Equal(t, "/testsuburl/assets/img/avatar_default.png",
4547
SizedAvatarLink("[email protected]", 100))
4648

4749
enableGravatar(t)

models/gpg_key_test.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ MkM/fdpyc2hY7Dl/+qFmN5MG5yGmMpQcX+RNNR222ibNC1D3wg==
103103
=i9b7
104104
-----END PGP PUBLIC KEY BLOCK-----`
105105
keys, err := checkArmoredGPGKeyString(testGPGArmor)
106+
if !assert.NotEmpty(t, keys) {
107+
return
108+
}
106109
ekey := keys[0]
107110
assert.NoError(t, err, "Could not parse a valid GPG armored key", ekey)
108111

@@ -189,6 +192,10 @@ Unknown GPG key with good email
189192
}
190193

191194
func TestCheckGPGUserEmail(t *testing.T) {
195+
assert.NoError(t, PrepareTestDatabase())
196+
197+
_ = AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
198+
192199
testEmailWithUpperCaseLetters := `-----BEGIN PGP PUBLIC KEY BLOCK-----
193200
Version: GnuPG v1
194201
@@ -222,9 +229,11 @@ Q0KHb+QcycSgbDx0ZAvdIacuKvBBcbxrsmFUI4LR+oIup0G9gUc0roPvr014jYQL
222229

223230
keys, err := AddGPGKey(1, testEmailWithUpperCaseLetters)
224231
assert.NoError(t, err)
225-
key := keys[0]
226-
if assert.Len(t, key.Emails, 1) {
227-
assert.Equal(t, "[email protected]", key.Emails[0].Email)
232+
if assert.NotEmpty(t, keys) {
233+
key := keys[0]
234+
if assert.Len(t, key.Emails, 1) {
235+
assert.Equal(t, "[email protected]", key.Emails[0].Email)
236+
}
228237
}
229238
}
230239

@@ -374,7 +383,9 @@ epiDVQ==
374383
`
375384
keys, err := checkArmoredGPGKeyString(testIssue6599)
376385
assert.NoError(t, err)
377-
ekey := keys[0]
378-
expire := getExpiryTime(ekey)
379-
assert.Equal(t, time.Unix(1586105389, 0), expire)
386+
if assert.NotEmpty(t, keys) {
387+
ekey := keys[0]
388+
expire := getExpiryTime(ekey)
389+
assert.Equal(t, time.Unix(1586105389, 0), expire)
390+
}
380391
}

models/issue_assignees_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ func TestUpdateAssignee(t *testing.T) {
6161
}
6262

6363
func TestMakeIDsFromAPIAssigneesToAdd(t *testing.T) {
64+
assert.NoError(t, PrepareTestDatabase())
65+
66+
_ = AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
67+
_ = AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
68+
6469
IDs, err := MakeIDsFromAPIAssigneesToAdd("", []string{""})
6570
assert.NoError(t, err)
6671
assert.Equal(t, []int64{}, IDs)

models/user_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ func TestCreateUser_Issue5882(t *testing.T) {
368368
}
369369

370370
func TestGetUserIDsByNames(t *testing.T) {
371+
assert.NoError(t, PrepareTestDatabase())
372+
371373
// ignore non existing
372374
IDs, err := GetUserIDsByNames([]string{"user1", "user2", "none_existing_user"}, true)
373375
assert.NoError(t, err)
@@ -380,6 +382,8 @@ func TestGetUserIDsByNames(t *testing.T) {
380382
}
381383

382384
func TestGetMaileableUsersByIDs(t *testing.T) {
385+
assert.NoError(t, PrepareTestDatabase())
386+
383387
results, err := GetMaileableUsersByIDs([]int64{1, 4}, false)
384388
assert.NoError(t, err)
385389
assert.Equal(t, 1, len(results))

modules/convert/user_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import (
88
"testing"
99

1010
"code.gitea.io/gitea/models"
11+
1112
"github.com/stretchr/testify/assert"
1213
)
1314

1415
func TestUser_ToUser(t *testing.T) {
16+
assert.NoError(t, models.PrepareTestDatabase())
1517

1618
user1 := models.AssertExistsAndLoadBean(t, &models.User{ID: 1, IsAdmin: true}).(*models.User)
1719

services/wiki/wiki_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ func TestRepository_AddWikiPage(t *testing.T) {
162162
}
163163

164164
func TestRepository_EditWikiPage(t *testing.T) {
165+
assert.NoError(t, models.PrepareTestDatabase())
166+
165167
const newWikiContent = "This is the new content"
166168
const commitMsg = "Commit message"
167169
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)

0 commit comments

Comments
 (0)