diff options
author | KN4CK3R <KN4CK3R@users.noreply.github.com> | 2021-05-12 06:13:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-12 00:13:42 -0400 |
commit | 3d7d750a999b72d422000154a0b1f2801614521e (patch) | |
tree | 59aa048dd42f9ffaea431093cd1e49d1c8d23cd7 /models/gpg_key_test.go | |
parent | 96b1315e6eaf04954383348cbbb4d1ef7810651b (diff) | |
download | gitea-3d7d750a999b72d422000154a0b1f2801614521e.tar.gz gitea-3d7d750a999b72d422000154a0b1f2801614521e.zip |
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 <art27@cantab.net>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'models/gpg_key_test.go')
-rw-r--r-- | models/gpg_key_test.go | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/models/gpg_key_test.go b/models/gpg_key_test.go index c9e0990933..f04eb8eadb 100644 --- a/models/gpg_key_test.go +++ b/models/gpg_key_test.go @@ -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) @@ -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 @@ -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, "user1@example.com", key.Emails[0].Email) + if assert.NotEmpty(t, keys) { + key := keys[0] + if assert.Len(t, key.Emails, 1) { + assert.Equal(t, "user1@example.com", key.Emails[0].Email) + } } } @@ -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) + } } |