diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-04-03 03:25:05 +0800 |
---|---|---|
committer | techknowlogick <matti@mdranta.net> | 2019-04-02 15:25:05 -0400 |
commit | 09fb036ad625ec5178319c30df47aac313fdbbe3 (patch) | |
tree | 4e5389c39924532023041d530b02a94d3bf987d2 /models/attachment_test.go | |
parent | 0a8e63c68292a08d8a7bc4fa397ae41235f086a7 (diff) | |
download | gitea-09fb036ad625ec5178319c30df47aac313fdbbe3.tar.gz gitea-09fb036ad625ec5178319c30df47aac313fdbbe3.zip |
fix upload attachments (#6481)
* fix upload attachments
* add migration for new column uploader_id on table attachment
* fix imports sequence
Diffstat (limited to 'models/attachment_test.go')
-rw-r--r-- | models/attachment_test.go | 29 |
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()) |