Merge remote-tracking branch 'origin/master'

pull/1257/head
HFO4 3 years ago
commit 862c7b2fd8

@ -46,5 +46,12 @@ jobs:
file: ./Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7
tags: ${{ steps.envs.outputs.tags }}
- name: Update Docker Hub Description
uses: peter-evans/dockerhub-description@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
repository: cloudreve/cloudreve
short-description: ${{ github.event.repository.description }}
- name: Image Digest
run: echo ${{ steps.docker_build.outputs.digest }}

@ -1,15 +0,0 @@
#!/bin/sh
GREEN='\033[0;32m'
RESET='\033[0m'
if [ ! -f /etc/cloudreve/aria2c.conf ]; then
echo -e "[${GREEN}aria2c${RESET}] aria2c config not found. Generating..."
secret=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 13)
echo -e "[${GREEN}aria2c${RESET}] Generated port: 6800, secret: $secret"
cat <<EOF > /etc/cloudreve/aria2c.conf
enable-rpc=true
rpc-listen-port=6800
rpc-secret=$secret
EOF
fi
aria2c --conf-path /etc/cloudreve/aria2c.conf -D
cloudreve

@ -266,7 +266,7 @@ func GetFilesByUploadSession(sessionID string, uid uint) (*File, error) {
// Rename 重命名文件
func (file *File) Rename(new string) error {
return DB.Model(&file).Update("name", new).Error
return DB.Model(&file).UpdateColumn("name", new).Error
}
// UpdatePicInfo 更新文件的图像信息

@ -2,11 +2,12 @@ package model
import (
"errors"
"testing"
"time"
"github.com/DATA-DOG/go-sqlmock"
"github.com/jinzhu/gorm"
"github.com/stretchr/testify/assert"
"testing"
"time"
)
func TestFile_Create(t *testing.T) {
@ -425,10 +426,11 @@ func TestGetFilesByUploadSession(t *testing.T) {
func TestFile_Updates(t *testing.T) {
asserts := assert.New(t)
file := File{Model: gorm.Model{ID: 1}}
// rename
{
mock.ExpectBegin()
mock.ExpectExec("UPDATE(.+)").WithArgs("newName", sqlmock.AnyArg(), 1).WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectExec("UPDATE(.+)files(.+)SET(.+)").WithArgs("newName", 1).WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectCommit()
err := file.Rename("newName")
asserts.NoError(mock.ExpectationsWereMet())

@ -298,10 +298,7 @@ func (folder *Folder) MoveFolderTo(dirs []uint, dstFolder *Folder) error {
// Rename 重命名目录
func (folder *Folder) Rename(new string) error {
if err := DB.Model(&folder).Update("name", new).Error; err != nil {
return err
}
return nil
return DB.Model(&folder).UpdateColumn("name", new).Error
}
/*

@ -584,3 +584,39 @@ func TestTraceRoot(t *testing.T) {
asserts.NoError(mock.ExpectationsWereMet())
}
}
func TestFolder_Rename(t *testing.T) {
asserts := assert.New(t)
folder := Folder{
Model: gorm.Model{
ID: 1,
},
Name: "test_name",
OwnerID: 1,
Position: "/test",
}
// 成功
{
mock.ExpectBegin()
mock.ExpectExec("UPDATE(.+)folders(.+)SET(.+)").
WithArgs("test_name_new", 1).
WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectCommit()
err := folder.Rename("test_name_new")
asserts.NoError(mock.ExpectationsWereMet())
asserts.NoError(err)
}
// 出现错误
{
mock.ExpectBegin()
mock.ExpectExec("UPDATE(.+)folders(.+)SET(.+)").
WithArgs("test_name_new", 1).
WillReturnError(errors.New("error"))
mock.ExpectRollback()
err := folder.Rename("test_name_new")
asserts.NoError(mock.ExpectationsWereMet())
asserts.Error(err)
}
}

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

Loading…
Cancel
Save