Fix: failed unit test

feat-album
HFO4 4 years ago
parent fc5c67cc20
commit 5a66af3105

@ -2,13 +2,6 @@ package local
import ( import (
"context" "context"
"io"
"io/ioutil"
"net/url"
"os"
"strings"
"testing"
model "github.com/cloudreve/Cloudreve/v3/models" model "github.com/cloudreve/Cloudreve/v3/models"
"github.com/cloudreve/Cloudreve/v3/pkg/auth" "github.com/cloudreve/Cloudreve/v3/pkg/auth"
"github.com/cloudreve/Cloudreve/v3/pkg/conf" "github.com/cloudreve/Cloudreve/v3/pkg/conf"
@ -16,6 +9,12 @@ import (
"github.com/cloudreve/Cloudreve/v3/pkg/util" "github.com/cloudreve/Cloudreve/v3/pkg/util"
"github.com/jinzhu/gorm" "github.com/jinzhu/gorm"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"io"
"io/ioutil"
"net/url"
"os"
"strings"
"testing"
) )
func TestHandler_Put(t *testing.T) { func TestHandler_Put(t *testing.T) {
@ -61,23 +60,33 @@ func TestHandler_Delete(t *testing.T) {
asserts := assert.New(t) asserts := assert.New(t)
handler := Driver{} handler := Driver{}
ctx := context.Background() ctx := context.Background()
filePath := util.RelativePath("test.file")
file, err := os.Create(util.RelativePath("test.file")) file, err := os.Create(filePath)
asserts.NoError(err) asserts.NoError(err)
_ = file.Close() _ = file.Close()
list, err := handler.Delete(ctx, []string{"test.file"}) list, err := handler.Delete(ctx, []string{"test.file"})
asserts.Equal([]string{}, list) asserts.Equal([]string{}, list)
asserts.NoError(err) asserts.NoError(err)
file, err = os.Create(util.RelativePath("test.file")) file, err = os.Create(filePath)
asserts.NoError(err)
_ = file.Close() _ = file.Close()
file, _ = os.OpenFile(filePath, os.O_RDWR, os.FileMode(0))
asserts.NoError(err)
list, err = handler.Delete(ctx, []string{"test.file", "test.notexist"}) list, err = handler.Delete(ctx, []string{"test.file", "test.notexist"})
asserts.Equal([]string{"test.notexist"}, list) file.Close()
asserts.Equal([]string{"test.file"}, list)
asserts.Error(err) asserts.Error(err)
list, err = handler.Delete(ctx, []string{"test.notexist"}) list, err = handler.Delete(ctx, []string{"test.notexist"})
asserts.Equal([]string{"test.notexist"}, list) asserts.Equal([]string{}, list)
asserts.NoError(err)
file, err = os.Create(filePath)
asserts.NoError(err)
list, err = handler.Delete(ctx, []string{"test.file"})
_ = file.Close()
asserts.Equal([]string{"test.file"}, list)
asserts.Error(err) asserts.Error(err)
} }

Loading…
Cancel
Save