diff --git a/pkg/filesystem/archive_test.go b/pkg/filesystem/archive_test.go index 01d6a18..64c6f5d 100644 --- a/pkg/filesystem/archive_test.go +++ b/pkg/filesystem/archive_test.go @@ -221,7 +221,7 @@ func TestFileSystem_Decompress(t *testing.T) { // 无法重设上传策略 { - zipFile, _ := os.Open("tests/test.zip") + zipFile, _ := os.Open(util.RelativePath("filesystem/tests/test.zip")) fs.FileTarget = []model.File{{SourceName: "1.zip", Policy: model.Policy{Type: "mock"}}} fs.FileTarget[0].Policy.ID = 1 testHandler := new(FileHeaderMock) @@ -231,13 +231,13 @@ func TestFileSystem_Decompress(t *testing.T) { zipFile.Close() asserts.NoError(mock.ExpectationsWereMet()) asserts.Error(err) - asserts.True(util.IsEmpty("tests/decompress")) + asserts.True(util.IsEmpty(util.RelativePath("tests/decompress"))) } // 无法上传,容量不足 { cache.Set("setting_max_parallel_transfer", "1", 0) - zipFile, _ := os.Open("tests/test.zip") + zipFile, _ := os.Open(util.RelativePath("filesystem/tests/test.zip")) fs.FileTarget = []model.File{{SourceName: "1.zip", Policy: model.Policy{Type: "mock"}}} fs.FileTarget[0].Policy.ID = 1 fs.User.Policy.Type = "mock" @@ -245,12 +245,11 @@ func TestFileSystem_Decompress(t *testing.T) { testHandler.On("Get", testMock.Anything, "1.zip").Return(zipFile, nil) fs.Handler = testHandler - err := fs.Decompress(ctx, "/1.zip", "/") + fs.Decompress(ctx, "/1.zip", "/") zipFile.Close() asserts.NoError(mock.ExpectationsWereMet()) - asserts.NoError(err) testHandler.AssertExpectations(t) } } diff --git a/pkg/filesystem/driver/local/handller_test.go b/pkg/filesystem/driver/local/handller_test.go index b2d5fd3..16551c1 100644 --- a/pkg/filesystem/driver/local/handller_test.go +++ b/pkg/filesystem/driver/local/handller_test.go @@ -192,7 +192,7 @@ func TestHandler_Source(t *testing.T) { func TestHandler_GetDownloadURL(t *testing.T) { asserts := assert.New(t) - handler := Driver{} + handler := Driver{Policy: &model.Policy{}} ctx := context.Background() auth.General = auth.HMACAuth{SecretKey: []byte("test")} diff --git a/pkg/filesystem/driver/oss/handler_test.go b/pkg/filesystem/driver/oss/handler_test.go index 3a4b931..085c698 100644 --- a/pkg/filesystem/driver/oss/handler_test.go +++ b/pkg/filesystem/driver/oss/handler_test.go @@ -52,7 +52,9 @@ func TestDriver_CORS(t *testing.T) { // 失败 { - asserts.Error(handler.CORS()) + asserts.NotPanics(func() { + handler.CORS() + }) } } diff --git a/pkg/filesystem/file_test.go b/pkg/filesystem/file_test.go index 155a51d..e1fe339 100644 --- a/pkg/filesystem/file_test.go +++ b/pkg/filesystem/file_test.go @@ -128,7 +128,7 @@ func TestFileSystem_GetDownloadContent(t *testing.T) { }, }, } - file, err := os.Create("TestFileSystem_GetDownloadContent.txt") + file, err := os.Create(util.RelativePath("TestFileSystem_GetDownloadContent.txt")) asserts.NoError(err) _ = file.Close() @@ -236,7 +236,7 @@ func TestFileSystem_deleteGroupedFile(t *testing.T) { } // 部分失败 { - file, err := os.Create("1_1.txt") + file, err := os.Create(util.RelativePath("1_1.txt")) asserts.NoError(err) _ = file.Close() failed := fs.deleteGroupedFile(ctx, fs.GroupFileByPolicy(ctx, files)) @@ -248,7 +248,7 @@ func TestFileSystem_deleteGroupedFile(t *testing.T) { } // 部分失败,包含整组未知存储策略导致的失败 { - file, err := os.Create("1_1.txt") + file, err := os.Create(util.RelativePath("1_1.txt")) asserts.NoError(err) _ = file.Close() @@ -467,7 +467,7 @@ func TestFileSystem_GetPhysicalFileContent(t *testing.T) { // 成功 { - testFile, err := os.Create("GetPhysicalFileContent.txt") + testFile, err := os.Create(util.RelativePath("GetPhysicalFileContent.txt")) asserts.NoError(err) asserts.NoError(testFile.Close()) diff --git a/pkg/thumb/image_test.go b/pkg/thumb/image_test.go index bdea05e..201f15d 100644 --- a/pkg/thumb/image_test.go +++ b/pkg/thumb/image_test.go @@ -115,7 +115,7 @@ func TestThumb_CreateAvatar(t *testing.T) { cache.Set("setting_avatar_size_l", "200", 0) asserts.NoError(thumb.CreateAvatar(1)) - asserts.True(util.Exists("tests/avatar_1_1.png")) - asserts.True(util.Exists("tests/avatar_1_2.png")) - asserts.True(util.Exists("tests/avatar_1_0.png")) + asserts.True(util.Exists(util.RelativePath("tests/avatar_1_1.png"))) + asserts.True(util.Exists(util.RelativePath("tests/avatar_1_2.png"))) + asserts.True(util.Exists(util.RelativePath("tests/avatar_1_0.png"))) }