Task Attachments #104

Merged
konrad merged 63 commits from feature/attachments into master 2019-10-16 20:52:31 +00:00
1 changed files with 42 additions and 1 deletions
Showing only changes of commit 41576b4c50 - Show all commits

View File

@ -19,12 +19,53 @@ package files
import (
"github.com/stretchr/testify/assert"
"io"
"os"
"testing"
)
func TestCreate(t *testing.T) {
type testfile struct {
content []byte
done bool
}
func (t *testfile) Read(p []byte) (n int, err error) {
if t.done {
return 0, io.EOF
}
copy(p, t.content)
t.done = true
return len(p), nil
}
func (t *testfile) Close() error {
return nil
}
type testauth struct {
id int64
}
func (a *testauth) GetID() int64 {
return a.id
}
func TestCreate(t *testing.T) {
initFixtures(t)
tf := &testfile{
content: []byte("testfile"),
}
ta := &testauth{id: 1}
_, err := Create(tf, "testfile", 100, ta)
assert.NoError(t, err)
// Check the file was created correctly
file := &File{ID: 2}
err = file.LoadFileMetaByID()
assert.NoError(t, err)
assert.Equal(t, int64(1), file.CreatedByID)
assert.Equal(t, "testfile", file.Name)
assert.Equal(t, int64(100), file.Size)
}
func TestFile_Delete(t *testing.T) {