Added test to check if the attachment file was inserted correctly
continuous-integration/drone/pr Build is passing
Details
continuous-integration/drone/pr Build is passing
Details
This commit is contained in:
parent
fcc5c20bf8
commit
f11e889102
|
@ -56,6 +56,7 @@ func (ta *TaskAttachment) NewAttachment(f io.ReadCloser, realname string, realsi
|
|||
|
||||
// Add an entry to the db
|
||||
ta.FileID = file.ID
|
||||
ta.CreatedByID = a.GetID()
|
||||
_, err = x.Insert(ta)
|
||||
if err != nil {
|
||||
// remove the uploaded file if adding it to the db fails
|
||||
|
|
|
@ -87,16 +87,24 @@ func TestTaskAttachment_NewAttachment(t *testing.T) {
|
|||
ta := TaskAttachment{
|
||||
TaskID: 1,
|
||||
}
|
||||
|
||||
tf := &testfile{
|
||||
content: []byte("testingstuff"),
|
||||
}
|
||||
err := ta.NewAttachment(tf, "testfile", 100, &User{ID: 1})
|
||||
assert.NoError(t, err)
|
||||
_, err = files.FileStat("/2")
|
||||
assert.False(t, os.IsNotExist(err))
|
||||
testuser := &User{ID: 1}
|
||||
|
||||
// Also assert created_by_id is correct in the files table
|
||||
err := ta.NewAttachment(tf, "testfile", 100, testuser)
|
||||
assert.NoError(t, err)
|
||||
_, err = files.FileStat("/2") // The new file has the id 2 since it's the second attachment
|
||||
assert.False(t, os.IsNotExist(err))
|
||||
assert.Equal(t, testuser.ID, ta.CreatedByID)
|
||||
|
||||
// Check the file was inserted correctly
|
||||
ta.File = &files.File{ID: ta.FileID}
|
||||
err = ta.File.LoadFileMetaByID()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, testuser.ID, ta.File.CreatedByID)
|
||||
assert.Equal(t, "testfile", ta.File.Name)
|
||||
assert.Equal(t, int64(100), ta.File.Size)
|
||||
|
||||
// Extra test for max size test
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue