You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.6 KiB
74 lines
1.6 KiB
5 years ago
|
package task
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"github.com/DATA-DOG/go-sqlmock"
|
||
|
model "github.com/HFO4/cloudreve/models"
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestRecord(t *testing.T) {
|
||
|
asserts := assert.New(t)
|
||
|
job := &TransferTask{
|
||
|
User: &model.User{Policy: model.Policy{Type: "unknown"}},
|
||
|
}
|
||
|
mock.ExpectBegin()
|
||
|
mock.ExpectExec("INSERT(.+)").WillReturnResult(sqlmock.NewResult(1, 1))
|
||
|
mock.ExpectCommit()
|
||
|
_, err := Record(job)
|
||
|
asserts.NoError(err)
|
||
|
}
|
||
|
|
||
|
func TestResume(t *testing.T) {
|
||
|
asserts := assert.New(t)
|
||
|
|
||
|
// 没有任务
|
||
|
{
|
||
|
mock.ExpectQuery("SELECT(.+)").WithArgs(Queued).WillReturnRows(sqlmock.NewRows([]string{"type"}))
|
||
|
Resume()
|
||
|
asserts.NoError(mock.ExpectationsWereMet())
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestGetJobFromModel(t *testing.T) {
|
||
|
asserts := assert.New(t)
|
||
|
|
||
|
// CompressTaskType
|
||
|
{
|
||
|
task := &model.Task{
|
||
|
Status: 0,
|
||
|
Type: CompressTaskType,
|
||
|
}
|
||
|
mock.ExpectQuery("SELECT(.+)users(.+)").WillReturnError(errors.New("error"))
|
||
|
job, err := GetJobFromModel(task)
|
||
|
asserts.NoError(mock.ExpectationsWereMet())
|
||
|
asserts.Nil(job)
|
||
|
asserts.Error(err)
|
||
|
}
|
||
|
// DecompressTaskType
|
||
|
{
|
||
|
task := &model.Task{
|
||
|
Status: 0,
|
||
|
Type: DecompressTaskType,
|
||
|
}
|
||
|
mock.ExpectQuery("SELECT(.+)users(.+)").WillReturnError(errors.New("error"))
|
||
|
job, err := GetJobFromModel(task)
|
||
|
asserts.NoError(mock.ExpectationsWereMet())
|
||
|
asserts.Nil(job)
|
||
|
asserts.Error(err)
|
||
|
}
|
||
|
// TransferTaskType
|
||
|
{
|
||
|
task := &model.Task{
|
||
|
Status: 0,
|
||
|
Type: TransferTaskType,
|
||
|
}
|
||
|
mock.ExpectQuery("SELECT(.+)users(.+)").WillReturnError(errors.New("error"))
|
||
|
job, err := GetJobFromModel(task)
|
||
|
asserts.NoError(mock.ExpectationsWereMet())
|
||
|
asserts.Nil(job)
|
||
|
asserts.Error(err)
|
||
|
}
|
||
|
}
|