mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Test: filesystem/file, filesystem, filesystem/hook, model/file/Create
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
@@ -16,3 +17,27 @@ func TestGetFileByPathAndName(t *testing.T) {
|
||||
asserts.Equal("1.cia", file.Name)
|
||||
asserts.NoError(mock.ExpectationsWereMet())
|
||||
}
|
||||
|
||||
func TestFile_Create(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
file := File{
|
||||
Name: "123",
|
||||
}
|
||||
|
||||
mock.ExpectBegin()
|
||||
mock.ExpectExec("INSERT(.+)").WillReturnResult(sqlmock.NewResult(5, 1))
|
||||
mock.ExpectCommit()
|
||||
fileID, err := file.Create()
|
||||
asserts.NoError(err)
|
||||
asserts.Equal(uint(5), fileID)
|
||||
asserts.Equal(uint(5), file.ID)
|
||||
asserts.NoError(mock.ExpectationsWereMet())
|
||||
|
||||
mock.ExpectBegin()
|
||||
mock.ExpectExec("INSERT(.+)").WillReturnError(errors.New("error"))
|
||||
mock.ExpectRollback()
|
||||
fileID, err = file.Create()
|
||||
asserts.Error(err)
|
||||
asserts.NoError(mock.ExpectationsWereMet())
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user