summaryrefslogtreecommitdiffstats
path: root/models/repo_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/repo_test.go')
-rw-r--r--models/repo_test.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/models/repo_test.go b/models/repo_test.go
index eee3997868..8411536d70 100644
--- a/models/repo_test.go
+++ b/models/repo_test.go
@@ -5,6 +5,11 @@
package models
import (
+ "bytes"
+ "crypto/md5"
+ "fmt"
+ "image"
+ "image/png"
"testing"
"code.gitea.io/gitea/modules/markup"
@@ -158,3 +163,51 @@ func TestTransferOwnership(t *testing.T) {
CheckConsistencyFor(t, &Repository{}, &User{}, &Team{})
}
+
+func TestUploadAvatar(t *testing.T) {
+
+ // Generate image
+ myImage := image.NewRGBA(image.Rect(0, 0, 1, 1))
+ var buff bytes.Buffer
+ png.Encode(&buff, myImage)
+
+ assert.NoError(t, PrepareTestDatabase())
+ repo := AssertExistsAndLoadBean(t, &Repository{ID: 10}).(*Repository)
+
+ err := repo.UploadAvatar(buff.Bytes())
+ assert.NoError(t, err)
+ assert.Equal(t, fmt.Sprintf("%d-%x", 10, md5.Sum(buff.Bytes())), repo.Avatar)
+}
+
+func TestUploadBigAvatar(t *testing.T) {
+
+ // Generate BIG image
+ myImage := image.NewRGBA(image.Rect(0, 0, 5000, 1))
+ var buff bytes.Buffer
+ png.Encode(&buff, myImage)
+
+ assert.NoError(t, PrepareTestDatabase())
+ repo := AssertExistsAndLoadBean(t, &Repository{ID: 10}).(*Repository)
+
+ err := repo.UploadAvatar(buff.Bytes())
+ assert.Error(t, err)
+}
+
+func TestDeleteAvatar(t *testing.T) {
+
+ // Generate image
+ myImage := image.NewRGBA(image.Rect(0, 0, 1, 1))
+ var buff bytes.Buffer
+ png.Encode(&buff, myImage)
+
+ assert.NoError(t, PrepareTestDatabase())
+ repo := AssertExistsAndLoadBean(t, &Repository{ID: 10}).(*Repository)
+
+ err := repo.UploadAvatar(buff.Bytes())
+ assert.NoError(t, err)
+
+ err = repo.DeleteAvatar()
+ assert.NoError(t, err)
+
+ assert.Equal(t, "", repo.Avatar)
+}