aboutsummaryrefslogtreecommitdiffstats
path: root/models/attachment_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/attachment_test.go')
-rw-r--r--models/attachment_test.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/models/attachment_test.go b/models/attachment_test.go
index be4baf3055..3984425e48 100644
--- a/models/attachment_test.go
+++ b/models/attachment_test.go
@@ -5,11 +5,40 @@
package models
import (
+ "os"
+ "path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
+func TestUploadAttachment(t *testing.T) {
+ assert.NoError(t, PrepareTestDatabase())
+
+ user := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
+
+ var fPath = "./attachment_test.go"
+ f, err := os.Open(fPath)
+ assert.NoError(t, err)
+ defer f.Close()
+
+ var buf = make([]byte, 1024)
+ n, err := f.Read(buf)
+ assert.NoError(t, err)
+ buf = buf[:n]
+
+ attach, err := NewAttachment(&Attachment{
+ UploaderID: user.ID,
+ Name: filepath.Base(fPath),
+ }, buf, f)
+ assert.NoError(t, err)
+
+ attachment, err := GetAttachmentByUUID(attach.UUID)
+ assert.NoError(t, err)
+ assert.EqualValues(t, user.ID, attachment.UploaderID)
+ assert.Equal(t, int64(0), attachment.DownloadCount)
+}
+
func TestIncreaseDownloadCount(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())