* 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 <art27@cantab.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io>release/v1.15
parent
96b1315e6e
commit
3d7d750a99
|
@ -40,8 +40,10 @@ func TestHashEmail(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSizedAvatarLink(t *testing.T) {
|
func TestSizedAvatarLink(t *testing.T) {
|
||||||
|
setting.AppSubURL = "/testsuburl"
|
||||||
|
|
||||||
disableGravatar()
|
disableGravatar()
|
||||||
assert.Equal(t, "/suburl/assets/img/avatar_default.png",
|
assert.Equal(t, "/testsuburl/assets/img/avatar_default.png",
|
||||||
SizedAvatarLink("gitea@example.com", 100))
|
SizedAvatarLink("gitea@example.com", 100))
|
||||||
|
|
||||||
enableGravatar(t)
|
enableGravatar(t)
|
||||||
|
|
|
@ -103,6 +103,9 @@ MkM/fdpyc2hY7Dl/+qFmN5MG5yGmMpQcX+RNNR222ibNC1D3wg==
|
||||||
=i9b7
|
=i9b7
|
||||||
-----END PGP PUBLIC KEY BLOCK-----`
|
-----END PGP PUBLIC KEY BLOCK-----`
|
||||||
keys, err := checkArmoredGPGKeyString(testGPGArmor)
|
keys, err := checkArmoredGPGKeyString(testGPGArmor)
|
||||||
|
if !assert.NotEmpty(t, keys) {
|
||||||
|
return
|
||||||
|
}
|
||||||
ekey := keys[0]
|
ekey := keys[0]
|
||||||
assert.NoError(t, err, "Could not parse a valid GPG armored key", ekey)
|
assert.NoError(t, err, "Could not parse a valid GPG armored key", ekey)
|
||||||
|
|
||||||
|
@ -189,6 +192,10 @@ Unknown GPG key with good email
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCheckGPGUserEmail(t *testing.T) {
|
func TestCheckGPGUserEmail(t *testing.T) {
|
||||||
|
assert.NoError(t, PrepareTestDatabase())
|
||||||
|
|
||||||
|
_ = AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||||
|
|
||||||
testEmailWithUpperCaseLetters := `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
testEmailWithUpperCaseLetters := `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||||
Version: GnuPG v1
|
Version: GnuPG v1
|
||||||
|
|
||||||
|
@ -222,11 +229,13 @@ Q0KHb+QcycSgbDx0ZAvdIacuKvBBcbxrsmFUI4LR+oIup0G9gUc0roPvr014jYQL
|
||||||
|
|
||||||
keys, err := AddGPGKey(1, testEmailWithUpperCaseLetters)
|
keys, err := AddGPGKey(1, testEmailWithUpperCaseLetters)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
if assert.NotEmpty(t, keys) {
|
||||||
key := keys[0]
|
key := keys[0]
|
||||||
if assert.Len(t, key.Emails, 1) {
|
if assert.Len(t, key.Emails, 1) {
|
||||||
assert.Equal(t, "user1@example.com", key.Emails[0].Email)
|
assert.Equal(t, "user1@example.com", key.Emails[0].Email)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCheckGParseGPGExpire(t *testing.T) {
|
func TestCheckGParseGPGExpire(t *testing.T) {
|
||||||
testIssue6599 := `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
testIssue6599 := `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||||
|
@ -374,7 +383,9 @@ epiDVQ==
|
||||||
`
|
`
|
||||||
keys, err := checkArmoredGPGKeyString(testIssue6599)
|
keys, err := checkArmoredGPGKeyString(testIssue6599)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
if assert.NotEmpty(t, keys) {
|
||||||
ekey := keys[0]
|
ekey := keys[0]
|
||||||
expire := getExpiryTime(ekey)
|
expire := getExpiryTime(ekey)
|
||||||
assert.Equal(t, time.Unix(1586105389, 0), expire)
|
assert.Equal(t, time.Unix(1586105389, 0), expire)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -61,6 +61,11 @@ func TestUpdateAssignee(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMakeIDsFromAPIAssigneesToAdd(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{""})
|
IDs, err := MakeIDsFromAPIAssigneesToAdd("", []string{""})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, []int64{}, IDs)
|
assert.Equal(t, []int64{}, IDs)
|
||||||
|
|
|
@ -368,6 +368,8 @@ func TestCreateUser_Issue5882(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetUserIDsByNames(t *testing.T) {
|
func TestGetUserIDsByNames(t *testing.T) {
|
||||||
|
assert.NoError(t, PrepareTestDatabase())
|
||||||
|
|
||||||
// ignore non existing
|
// ignore non existing
|
||||||
IDs, err := GetUserIDsByNames([]string{"user1", "user2", "none_existing_user"}, true)
|
IDs, err := GetUserIDsByNames([]string{"user1", "user2", "none_existing_user"}, true)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -380,6 +382,8 @@ func TestGetUserIDsByNames(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetMaileableUsersByIDs(t *testing.T) {
|
func TestGetMaileableUsersByIDs(t *testing.T) {
|
||||||
|
assert.NoError(t, PrepareTestDatabase())
|
||||||
|
|
||||||
results, err := GetMaileableUsersByIDs([]int64{1, 4}, false)
|
results, err := GetMaileableUsersByIDs([]int64{1, 4}, false)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, 1, len(results))
|
assert.Equal(t, 1, len(results))
|
||||||
|
|
|
@ -8,10 +8,12 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUser_ToUser(t *testing.T) {
|
func TestUser_ToUser(t *testing.T) {
|
||||||
|
assert.NoError(t, models.PrepareTestDatabase())
|
||||||
|
|
||||||
user1 := models.AssertExistsAndLoadBean(t, &models.User{ID: 1, IsAdmin: true}).(*models.User)
|
user1 := models.AssertExistsAndLoadBean(t, &models.User{ID: 1, IsAdmin: true}).(*models.User)
|
||||||
|
|
||||||
|
|
|
@ -162,6 +162,8 @@ func TestRepository_AddWikiPage(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRepository_EditWikiPage(t *testing.T) {
|
func TestRepository_EditWikiPage(t *testing.T) {
|
||||||
|
assert.NoError(t, models.PrepareTestDatabase())
|
||||||
|
|
||||||
const newWikiContent = "This is the new content"
|
const newWikiContent = "This is the new content"
|
||||||
const commitMsg = "Commit message"
|
const commitMsg = "Commit message"
|
||||||
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
|
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
|
||||||
|
|
Loading…
Reference in New Issue