aliyunpan/internal/syncdrive/file_action_task_mgr_test.go

70 lines
1.8 KiB
Go
Raw Normal View History

2022-06-01 21:55:03 +08:00
package syncdrive
import (
"fmt"
"github.com/tickstep/aliyunpan-api/aliyunpan"
"github.com/tickstep/aliyunpan/internal/utils"
"github.com/tickstep/library-go/logger"
"os"
"testing"
"time"
)
func TestFileActionMgrStart(t *testing.T) {
2022-06-10 13:55:00 +08:00
refreshToken := "1640cc2d4ea...cb4d6242161a7"
2022-06-01 21:55:03 +08:00
webToken, err := aliyunpan.GetAccessTokenFromRefreshToken(refreshToken)
if err != nil {
fmt.Println("get acccess token error")
return
}
// pan client
panClient := aliyunpan.NewPanClient(*webToken, aliyunpan.AppLoginToken{})
user, _ := panClient.GetUserInfo()
task := &SyncTask{
Id: "5b2d7c10-e927-4e72-8f9d-5abb3bb04814",
DriveId: user.FileDriveId,
2022-06-10 13:55:00 +08:00
LocalFolderPath: "D:\\smb\\feny\\goprojects\\dev\\NS游戏备份",
2022-06-01 21:55:03 +08:00
PanFolderPath: "/sync_drive",
Mode: "sync",
LastSyncTime: "2022-05-26 19:29:19",
2022-06-10 13:55:00 +08:00
syncDbFolderPath: "D:\\smb\\feny\\goprojects\\dev\\sync_drive",
2022-06-01 21:55:03 +08:00
panClient: panClient,
2022-08-13 16:54:42 +08:00
syncOption: SyncOption{
FileDownloadParallel: 2,
FileUploadParallel: 2,
FileDownloadBlockSize: int64(256 * 1024),
FileUploadBlockSize: aliyunpan.DefaultChunkSize,
UseInternalUrl: false,
MaxDownloadRate: 0,
MaxUploadRate: 0,
},
2022-06-01 21:55:03 +08:00
}
2022-06-10 13:55:00 +08:00
task.setupDb()
2022-06-01 21:55:03 +08:00
2022-08-13 16:54:42 +08:00
ft := NewFileActionTaskManager(task)
2022-06-01 21:55:03 +08:00
ft.Start()
//go func() {
// time.Sleep(10 * time.Second)
// task.Stop()
//}()
time.Sleep(50 * time.Minute)
ft.Stop()
}
func TestFileTime(t *testing.T) {
ts := utils.ParseTimeStr("2013-01-11 12:15:07")
//ts = time.Now()
if err := os.Chtimes("/Volumes/Downloads/dev/upload/password.key", ts, ts); err != nil {
logger.Verbosef(err.Error())
}
}
func TestLocalFileTime(t *testing.T) {
if file, er := os.Stat("/Volumes/Downloads/dev/upload/password.key"); er == nil {
fmt.Println(file.ModTime().Format("2006-01-02 15:04:05"))
}
}