Added tests for creating a file
continuous-integration/drone/pr Build is failing Details

This commit is contained in:
kolaente 2019-10-13 16:55:18 +02:00
parent f6f810e28b
commit 41576b4c50
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 42 additions and 1 deletions

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) {