Cloudreve/models/folder_test.go

25 lines
679 B
Go
Raw Normal View History

2019-11-18 19:09:56 +08:00
package model
import (
2019-11-18 19:32:06 +08:00
"github.com/DATA-DOG/go-sqlmock"
2019-11-18 19:09:56 +08:00
"github.com/stretchr/testify/assert"
"testing"
)
func TestGetFolderByPath(t *testing.T) {
asserts := assert.New(t)
2019-11-18 19:32:06 +08:00
folderRows := sqlmock.NewRows([]string{"id", "name"}).
AddRow(1, "test")
mock.ExpectQuery("^SELECT (.+)").WillReturnRows(folderRows)
folder, _ := GetFolderByPath("/测试/test", 1)
asserts.Equal("test", folder.Name)
asserts.NoError(mock.ExpectationsWereMet())
2019-11-18 19:09:56 +08:00
2019-11-18 19:32:06 +08:00
folderRows = sqlmock.NewRows([]string{"id", "name"})
mock.ExpectQuery("^SELECT (.+)").WillReturnRows(folderRows)
folder, err := GetFolderByPath("/测试/test", 1)
asserts.Error(err)
2019-11-18 19:09:56 +08:00
asserts.NoError(mock.ExpectationsWereMet())
}