Skip to content

Fix individual tests (addition to #15802) #15818

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion models/avatar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ func TestHashEmail(t *testing.T) {
}

func TestSizedAvatarLink(t *testing.T) {
setting.AppSubURL = "/testsuburl"

disableGravatar()
assert.Equal(t, "/suburl/assets/img/avatar_default.png",
assert.Equal(t, "/testsuburl/assets/img/avatar_default.png",
SizedAvatarLink("[email protected]", 100))

enableGravatar(t)
Expand Down
23 changes: 17 additions & 6 deletions models/gpg_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ MkM/fdpyc2hY7Dl/+qFmN5MG5yGmMpQcX+RNNR222ibNC1D3wg==
=i9b7
-----END PGP PUBLIC KEY BLOCK-----`
keys, err := checkArmoredGPGKeyString(testGPGArmor)
if !assert.NotEmpty(t, keys) {
return
}
ekey := keys[0]
assert.NoError(t, err, "Could not parse a valid GPG armored key", ekey)

Expand Down Expand Up @@ -189,6 +192,10 @@ Unknown GPG key with good email
}

func TestCheckGPGUserEmail(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())

_ = AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)

testEmailWithUpperCaseLetters := `-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1

Expand Down Expand Up @@ -222,9 +229,11 @@ Q0KHb+QcycSgbDx0ZAvdIacuKvBBcbxrsmFUI4LR+oIup0G9gUc0roPvr014jYQL

keys, err := AddGPGKey(1, testEmailWithUpperCaseLetters)
assert.NoError(t, err)
key := keys[0]
if assert.Len(t, key.Emails, 1) {
assert.Equal(t, "[email protected]", key.Emails[0].Email)
if assert.NotEmpty(t, keys) {
key := keys[0]
if assert.Len(t, key.Emails, 1) {
assert.Equal(t, "[email protected]", key.Emails[0].Email)
}
}
}

Expand Down Expand Up @@ -374,7 +383,9 @@ epiDVQ==
`
keys, err := checkArmoredGPGKeyString(testIssue6599)
assert.NoError(t, err)
ekey := keys[0]
expire := getExpiryTime(ekey)
assert.Equal(t, time.Unix(1586105389, 0), expire)
if assert.NotEmpty(t, keys) {
ekey := keys[0]
expire := getExpiryTime(ekey)
assert.Equal(t, time.Unix(1586105389, 0), expire)
}
}
5 changes: 5 additions & 0 deletions models/issue_assignees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ func TestUpdateAssignee(t *testing.T) {
}

func TestMakeIDsFromAPIAssigneesToAdd(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())

_ = AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
_ = AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)

IDs, err := MakeIDsFromAPIAssigneesToAdd("", []string{""})
assert.NoError(t, err)
assert.Equal(t, []int64{}, IDs)
Expand Down
4 changes: 4 additions & 0 deletions models/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ func TestCreateUser_Issue5882(t *testing.T) {
}

func TestGetUserIDsByNames(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())

// ignore non existing
IDs, err := GetUserIDsByNames([]string{"user1", "user2", "none_existing_user"}, true)
assert.NoError(t, err)
Expand All @@ -380,6 +382,8 @@ func TestGetUserIDsByNames(t *testing.T) {
}

func TestGetMaileableUsersByIDs(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())

results, err := GetMaileableUsersByIDs([]int64{1, 4}, false)
assert.NoError(t, err)
assert.Equal(t, 1, len(results))
Expand Down
2 changes: 2 additions & 0 deletions modules/convert/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import (
"testing"

"code.gitea.io/gitea/models"

"github.com/stretchr/testify/assert"
)

func TestUser_ToUser(t *testing.T) {
assert.NoError(t, models.PrepareTestDatabase())

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

Expand Down
2 changes: 2 additions & 0 deletions services/wiki/wiki_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ func TestRepository_AddWikiPage(t *testing.T) {
}

func TestRepository_EditWikiPage(t *testing.T) {
assert.NoError(t, models.PrepareTestDatabase())

const newWikiContent = "This is the new content"
const commitMsg = "Commit message"
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
Expand Down