|
|
@ -3,11 +3,12 @@ package filesystem
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"errors"
|
|
|
|
"github.com/cloudreve/Cloudreve/v3/pkg/filesystem/response"
|
|
|
|
|
|
|
|
testMock "github.com/stretchr/testify/mock"
|
|
|
|
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/cloudreve/Cloudreve/v3/pkg/filesystem/response"
|
|
|
|
|
|
|
|
testMock "github.com/stretchr/testify/mock"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/DATA-DOG/go-sqlmock"
|
|
|
|
"github.com/DATA-DOG/go-sqlmock"
|
|
|
|
model "github.com/cloudreve/Cloudreve/v3/models"
|
|
|
|
model "github.com/cloudreve/Cloudreve/v3/models"
|
|
|
|
"github.com/cloudreve/Cloudreve/v3/pkg/cache"
|
|
|
|
"github.com/cloudreve/Cloudreve/v3/pkg/cache"
|
|
|
@ -676,8 +677,8 @@ func TestFileSystem_Rename(t *testing.T) {
|
|
|
|
WithArgs(10, 1).
|
|
|
|
WithArgs(10, 1).
|
|
|
|
WillReturnRows(sqlmock.NewRows([]string{"id", "name"}).AddRow(10, "old.text"))
|
|
|
|
WillReturnRows(sqlmock.NewRows([]string{"id", "name"}).AddRow(10, "old.text"))
|
|
|
|
mock.ExpectBegin()
|
|
|
|
mock.ExpectBegin()
|
|
|
|
mock.ExpectExec("UPDATE(.+)files(.+)").
|
|
|
|
mock.ExpectExec("UPDATE(.+)files(.+)SET(.+)").
|
|
|
|
WithArgs("new.txt", sqlmock.AnyArg(), 10).
|
|
|
|
WithArgs("new.txt", 10).
|
|
|
|
WillReturnResult(sqlmock.NewResult(1, 1))
|
|
|
|
WillReturnResult(sqlmock.NewResult(1, 1))
|
|
|
|
mock.ExpectCommit()
|
|
|
|
mock.ExpectCommit()
|
|
|
|
err := fs.Rename(ctx, []uint{}, []uint{10}, "new.txt")
|
|
|
|
err := fs.Rename(ctx, []uint{}, []uint{10}, "new.txt")
|
|
|
@ -702,8 +703,8 @@ func TestFileSystem_Rename(t *testing.T) {
|
|
|
|
WithArgs(10, 1).
|
|
|
|
WithArgs(10, 1).
|
|
|
|
WillReturnRows(sqlmock.NewRows([]string{"id", "name"}).AddRow(10, "old.text"))
|
|
|
|
WillReturnRows(sqlmock.NewRows([]string{"id", "name"}).AddRow(10, "old.text"))
|
|
|
|
mock.ExpectBegin()
|
|
|
|
mock.ExpectBegin()
|
|
|
|
mock.ExpectExec("UPDATE(.+)files(.+)").
|
|
|
|
mock.ExpectExec("UPDATE(.+)files(.+)SET(.+)").
|
|
|
|
WithArgs("new.txt", sqlmock.AnyArg(), 10).
|
|
|
|
WithArgs("new.txt", 10).
|
|
|
|
WillReturnError(errors.New("error"))
|
|
|
|
WillReturnError(errors.New("error"))
|
|
|
|
mock.ExpectRollback()
|
|
|
|
mock.ExpectRollback()
|
|
|
|
err := fs.Rename(ctx, []uint{}, []uint{10}, "new.txt")
|
|
|
|
err := fs.Rename(ctx, []uint{}, []uint{10}, "new.txt")
|
|
|
@ -718,8 +719,8 @@ func TestFileSystem_Rename(t *testing.T) {
|
|
|
|
WithArgs(10, 1).
|
|
|
|
WithArgs(10, 1).
|
|
|
|
WillReturnRows(sqlmock.NewRows([]string{"id", "name"}).AddRow(10, "old"))
|
|
|
|
WillReturnRows(sqlmock.NewRows([]string{"id", "name"}).AddRow(10, "old"))
|
|
|
|
mock.ExpectBegin()
|
|
|
|
mock.ExpectBegin()
|
|
|
|
mock.ExpectExec("UPDATE(.+)folders(.+)").
|
|
|
|
mock.ExpectExec("UPDATE(.+)folders(.+)SET(.+)").
|
|
|
|
WithArgs("new", sqlmock.AnyArg(), 10).
|
|
|
|
WithArgs("new", 10).
|
|
|
|
WillReturnResult(sqlmock.NewResult(1, 1))
|
|
|
|
WillReturnResult(sqlmock.NewResult(1, 1))
|
|
|
|
mock.ExpectCommit()
|
|
|
|
mock.ExpectCommit()
|
|
|
|
err := fs.Rename(ctx, []uint{10}, []uint{}, "new")
|
|
|
|
err := fs.Rename(ctx, []uint{10}, []uint{}, "new")
|
|
|
@ -744,8 +745,8 @@ func TestFileSystem_Rename(t *testing.T) {
|
|
|
|
WithArgs(10, 1).
|
|
|
|
WithArgs(10, 1).
|
|
|
|
WillReturnRows(sqlmock.NewRows([]string{"id", "name"}).AddRow(10, "old"))
|
|
|
|
WillReturnRows(sqlmock.NewRows([]string{"id", "name"}).AddRow(10, "old"))
|
|
|
|
mock.ExpectBegin()
|
|
|
|
mock.ExpectBegin()
|
|
|
|
mock.ExpectExec("UPDATE(.+)folders(.+)").
|
|
|
|
mock.ExpectExec("UPDATE(.+)folders(.+)SET(.+)").
|
|
|
|
WithArgs("new", sqlmock.AnyArg(), 10).
|
|
|
|
WithArgs("new", 10).
|
|
|
|
WillReturnError(errors.New("error"))
|
|
|
|
WillReturnError(errors.New("error"))
|
|
|
|
mock.ExpectRollback()
|
|
|
|
mock.ExpectRollback()
|
|
|
|
err := fs.Rename(ctx, []uint{10}, []uint{}, "new")
|
|
|
|
err := fs.Rename(ctx, []uint{10}, []uint{}, "new")
|
|
|
|