Task Attachments #104
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue