Fix: failed test due to relative path

pull/247/head
HFO4 4 years ago
parent 37de715541
commit 71876a79cd

@ -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)
}
}

@ -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")}

@ -52,7 +52,9 @@ func TestDriver_CORS(t *testing.T) {
// 失败
{
asserts.Error(handler.CORS())
asserts.NotPanics(func() {
handler.CORS()
})
}
}

@ -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())

@ -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")))
}

Loading…
Cancel
Save