Added getting the actual file
continuous-integration/drone/pr Build is failing Details

This commit is contained in:
kolaente 2019-10-10 20:46:43 +02:00
parent 81068a810c
commit 787d1df872
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
3 changed files with 20 additions and 3 deletions

View File

@ -17,6 +17,7 @@
package files
import (
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/log"
"github.com/spf13/afero"
@ -39,6 +40,12 @@ func InitFileHandler() {
func InitTestFileHandler() {
fs = afero.NewMemMapFs()
afs = &afero.Afero{Fs: fs}
// Add some fixed test files
err := afero.WriteFile(afs, config.FilesBasePath.GetString()+"/1", []byte("testfile1"), 0644)
if err != nil {
log.Fatal("Error creating test file: ", err)
}
}
// InitTests handles the actual bootstrapping of the test env

View File

@ -38,7 +38,7 @@ type File struct {
InsertedUnix int64 `xorm:"created" json:"inserted_unix"`
CreatedByID int64 `xorm:"int(11) not null" json:"-"`
File *afero.File `xorm:"-" json:"-"`
File afero.File `xorm:"-" json:"-"`
}
// TableName is the table name for the files table
@ -52,7 +52,7 @@ func (f *File) getFileName() string {
// LoadFileByID returns a file by its ID
func (f *File) LoadFileByID() (err error) {
*f.File, err = afs.Open(f.getFileName())
f.File, err = afs.Open(f.getFileName())
return
}

View File

@ -18,6 +18,7 @@
package models
import (
"code.vikunja.io/api/pkg/config"
"github.com/stretchr/testify/assert"
"testing"
)
@ -31,5 +32,14 @@ func TestTaskAttachment_ReadOne(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, ta.File)
assert.True(t, ta.File.ID == ta.FileID && ta.FileID != 0)
// TODO: check file content
// Load the actual attachment file and check its content
err = ta.File.LoadFileByID()
assert.NoError(t, err)
assert.Equal(t, config.FilesBasePath.GetString()+"/1", ta.File.File.Name())
content := make([]byte, 9)
read, err := ta.File.File.Read(content)
assert.NoError(t, err)
assert.Equal(t, 9, read)
assert.Equal(t, []byte("testfile1"), content)
}