Browse Source

调整结构,解决单元测试遇到的嵌套调用问题

Signed-off-by: allan716 <[email protected]>
allan716 3 years ago
parent
commit
4ac979bff5

+ 1 - 2
cmd/chinesesubfinder/main.go

@@ -4,7 +4,6 @@ import (
 	"fmt"
 	"github.com/allanpk716/ChineseSubFinder/internal/backend"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/cron_helper"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg/folder_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/global_value"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
@@ -19,7 +18,7 @@ func init() {
 
 	global_value.AppVersion = AppVersion
 
-	global_value.ConfigRootDirFPath = folder_helper.GetConfigRootDirFPath()
+	global_value.ConfigRootDirFPath = my_util.GetConfigRootDirFPath()
 
 	if my_util.OSCheck() == false {
 		panic(`You should search runtime.GOOS in the project, Implement unimplemented function`)

+ 1 - 2
internal/dao/init.go

@@ -4,7 +4,6 @@ import (
 	"errors"
 	"fmt"
 	"github.com/allanpk716/ChineseSubFinder/internal/models"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg/folder_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"gorm.io/driver/sqlite"
@@ -76,7 +75,7 @@ func InitDb() error {
 }
 
 func getDbName() string {
-	return filepath.Join(folder_helper.GetConfigRootDirFPath(), dbFileName)
+	return filepath.Join(my_util.GetConfigRootDirFPath(), dbFileName)
 }
 
 var (

+ 2 - 3
internal/logic/downloader_helper/downloader_helper.go

@@ -3,7 +3,6 @@ package downloader_helper
 import (
 	subSupplier "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/downloader"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg/folder_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/notify_center"
@@ -91,12 +90,12 @@ func (d *DownloaderHelper) Start() error {
 
 	d.logger.Infoln("Will Scan SubFixCache Folder, Clear files that are more than 7 * 24 hours old")
 	// 清理多天没有使用的时间轴字幕校正缓存文件
-	rootSubFixCache, err := folder_helper.GetRootSubFixCacheFolder()
+	rootSubFixCache, err := my_util.GetRootSubFixCacheFolder()
 	if err != nil {
 		d.logger.Errorln("GetRootSubFixCacheFolder", err)
 		return err
 	}
-	err = folder_helper.ClearIdleSubFixCacheFolder(rootSubFixCache, 7*24*time.Hour)
+	err = my_util.ClearIdleSubFixCacheFolder(rootSubFixCache, 7*24*time.Hour)
 	if err != nil {
 		d.logger.Errorln("ClearIdleSubFixCacheFolder", err)
 		return err

+ 1 - 2
internal/logic/forced_scan_and_down_sub/forced_scan_and_down_sub.go

@@ -3,7 +3,6 @@ package forced_scan_and_down_sub
 import (
 	"errors"
 	"fmt"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg/folder_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"os"
 	"path/filepath"
@@ -31,7 +30,7 @@ you needd implement getSpeFileName() in internal/logic/forced_scan_and_down_sub/
 
 func getSpeFileName() string {
 
-	return filepath.Join(folder_helper.GetConfigRootDirFPath(), specialFileNameWindows)
+	return filepath.Join(my_util.GetConfigRootDirFPath(), specialFileNameWindows)
 }
 
 /*

+ 1 - 2
internal/logic/restore_fix_timeline_bk/restore_fix_timeline_bk.go

@@ -1,7 +1,6 @@
 package restore_fix_timeline_bk
 
 import (
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg/folder_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"os"
 	"path/filepath"
@@ -25,7 +24,7 @@ func CheckSpeFile() (bool, error) {
 }
 
 func getSpeFileName() string {
-	return filepath.Join(folder_helper.GetConfigRootDirFPath(), specialFileName)
+	return filepath.Join(my_util.GetConfigRootDirFPath(), specialFileName)
 }
 
 /*

+ 1 - 2
internal/logic/sub_supplier/subhd/subhd.go

@@ -7,7 +7,6 @@ import (
 	"github.com/Tnze/go.num/v2/zh"
 	"github.com/allanpk716/ChineseSubFinder/internal/common"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/decode"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg/folder_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/notify_center"
@@ -669,7 +668,7 @@ search:
 
 	if s.debugMode == true {
 		//截圖保存
-		nowProcessRoot, err := folder_helper.GetRootDebugFolder()
+		nowProcessRoot, err := my_util.GetRootDebugFolder()
 		if err == nil {
 			page.MustScreenshot(filepath.Join(nowProcessRoot, "result.png"))
 		} else {

+ 2 - 2
internal/pkg/debug_view/debug_view.go

@@ -2,7 +2,7 @@ package debug_view
 
 import (
 	"fmt"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg/folder_helper"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/vad"
 	"github.com/go-echarts/go-echarts/v2/charts"
@@ -42,7 +42,7 @@ func SaveDebugChartBase(vadList []vad.VADInfo, title, subTitle string) error {
 	line.SetXAxis(xAxis).
 		AddSeries("VAD", lineData)
 
-	rootDebugFolder, err := folder_helper.GetRootDebugFolder()
+	rootDebugFolder, err := my_util.GetRootDebugFolder()
 	if err != nil {
 		return err
 	}

+ 48 - 0
internal/pkg/decode/decode_test.go

@@ -2,7 +2,9 @@ package decode
 
 import (
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/unit_test_helper"
+	"github.com/allanpk716/ChineseSubFinder/internal/types"
 	"path/filepath"
+	"reflect"
 	"testing"
 )
 
@@ -108,3 +110,49 @@ func TestGetNumber2int(t *testing.T) {
 		t.Error("not the same")
 	}
 }
+
+func TestGetImdbInfo4SeriesDir(t *testing.T) {
+
+	type args struct {
+		seriesDir string
+	}
+	tests := []struct {
+		name    string
+		args    args
+		want    types.VideoIMDBInfo
+		wantErr bool
+	}{
+		{
+			name: "Loki",
+			args: args{seriesDir: unit_test_helper.GetTestDataResourceRootPath([]string{"series", "Loki"}, 4, false)},
+			want: types.VideoIMDBInfo{
+				ImdbId:      "tt9140554",
+				Title:       "Loki",
+				ReleaseDate: "2021-06-09",
+			},
+			wantErr: false,
+		},
+		{
+			name: "辛普森一家",
+			args: args{seriesDir: unit_test_helper.GetTestDataResourceRootPath([]string{"series", "辛普森一家"}, 4, false)},
+			want: types.VideoIMDBInfo{
+				ImdbId:      "tt9140554",
+				Title:       "Loki",
+				ReleaseDate: "2021-06-09",
+			},
+			wantErr: false,
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			got, err := GetImdbInfo4SeriesDir(tt.args.seriesDir)
+			if (err != nil) != tt.wantErr {
+				t.Errorf("GetImdbInfo4SeriesDir() error = %v, wantErr %v", err, tt.wantErr)
+				return
+			}
+			if !reflect.DeepEqual(got, tt.want) {
+				t.Errorf("GetImdbInfo4SeriesDir() got = %v, want %v", got, tt.want)
+			}
+		})
+	}
+}

+ 2 - 3
internal/pkg/downloader/downloader.go

@@ -12,7 +12,6 @@ import (
 	seriesHelper "github.com/allanpk716/ChineseSubFinder/internal/logic/series_helper"
 	subSupplier "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_timeline_fixer"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg/folder_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/settings"
@@ -201,7 +200,7 @@ func (d *Downloader) RefreshEmbySubList() error {
 func (d *Downloader) DownloadSub4Movie() error {
 	defer func() {
 		// 所有的电影字幕下载完成,抉择完成,需要清理缓存目录
-		err := folder_helper.ClearRootTmpFolder()
+		err := my_util.ClearRootTmpFolder()
 		if err != nil {
 			d.log.Error("ClearRootTmpFolder", err)
 		}
@@ -290,7 +289,7 @@ func (d *Downloader) DownloadSub4Series() error {
 	var err error
 	defer func() {
 		// 所有的连续剧字幕下载完成,抉择完成,需要清理缓存目录
-		err := folder_helper.ClearRootTmpFolder()
+		err := my_util.ClearRootTmpFolder()
 		if err != nil {
 			d.log.Error("ClearRootTmpFolder", err)
 		}

+ 2 - 3
internal/pkg/downloader/downloader_things.go

@@ -2,7 +2,6 @@ package downloader
 
 import (
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/decode"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg/folder_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	subcommon "github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_formatter/common"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_helper"
@@ -27,7 +26,7 @@ func (d *Downloader) oneVideoSelectBestSub(oneVideoFullPath string, organizeSubF
 	// 调试缓存,把下载好的字幕写到对应的视频目录下,方便调试
 	if d.settings.AdvancedSettings.DebugMode == true {
 
-		err = folder_helper.CopyFiles2DebugFolder([]string{videoFileName}, organizeSubFiles)
+		err = my_util.CopyFiles2DebugFolder([]string{videoFileName}, organizeSubFiles)
 		if err != nil {
 			d.log.Errorln("copySubFile2DesFolder", err)
 		}
@@ -129,7 +128,7 @@ func (d *Downloader) saveFullSeasonSub(seriesInfo *series.SeriesInfo, organizeSu
 		for _, sub := range subs {
 			subFileName := filepath.Base(sub)
 
-			newSeasonSubRootPath, err := folder_helper.GetDebugFolderByName([]string{
+			newSeasonSubRootPath, err := my_util.GetDebugFolderByName([]string{
 				filepath.Base(seriesInfo.DirPath),
 				"Sub_" + seasonKey})
 			if err != nil {

+ 1 - 2
internal/pkg/ffmpeg_helper/ffmpeg_helper.go

@@ -7,7 +7,6 @@ import (
 	"github.com/allanpk716/ChineseSubFinder/internal/common"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/ass"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/srt"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg/folder_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/language"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
@@ -97,7 +96,7 @@ func (f *FFMPEGHelper) GetFFMPEGInfo(videoFileFullPath string, exportType Export
 		// 说明缓存不存在,需要导出,这里需要注意,如果导出失败了,这个文件夹要清理掉
 		if my_util.IsDir(nowCacheFolderPath) == true {
 			// 如果存在则,先清空一个这个文件夹
-			err = folder_helper.ClearFolder(nowCacheFolderPath)
+			err = my_util.ClearFolder(nowCacheFolderPath)
 			if err != nil {
 				bok = false
 				return bok, nil, err

+ 1 - 2
internal/pkg/ffmpeg_helper/ffmpeg_info.go

@@ -2,7 +2,6 @@ package ffmpeg_helper
 
 import (
 	"github.com/allanpk716/ChineseSubFinder/internal/common"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg/folder_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_helper"
@@ -33,7 +32,7 @@ func NewFFMPEGInfo(videoFullPath string) *FFMPEGInfo {
 // csf-cache/当前的视频文件名(不带后缀)
 func (f *FFMPEGInfo) GetCacheFolderFPath() (string, error) {
 	noExtVideoName := strings.ReplaceAll(filepath.Base(f.VideoFullPath), filepath.Ext(f.VideoFullPath), "")
-	return folder_helper.GetSubFixCacheFolderByName(noExtVideoName)
+	return my_util.GetSubFixCacheFolderByName(noExtVideoName)
 }
 
 // IsExported 是否已经导出过,如果没有导出或者导出不完整为 false

+ 3 - 80
internal/pkg/folder_helper/folder.go → internal/pkg/my_util/folder.go

@@ -1,15 +1,12 @@
-package folder_helper
+package my_util
 
 import (
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/get_access_time"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/global_value"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"os"
 	"path/filepath"
 	"runtime"
-	"strconv"
-	"strings"
 	"time"
 )
 
@@ -65,7 +62,7 @@ func CopyFiles2DebugFolder(names []string, subFiles []string) error {
 	// 复制下载在 tmp 文件夹中的字幕文件到视频文件夹下面
 	for _, subFile := range subFiles {
 		newFn := filepath.Join(debugFolderByName, filepath.Base(subFile))
-		err = my_util.CopyFile(subFile, newFn)
+		err = CopyFile(subFile, newFn)
 		if err != nil {
 			return err
 		}
@@ -218,80 +215,6 @@ func ClearFolder(folderFullPath string) error {
 	return nil
 }
 
-// ClearFolderEx 清空文件夹,文件夹名称有特殊之处,Hour-min-Nanosecond 的命名方式
-// 如果调用的时候,已存在的文件夹的时间 min < 5 那么则清理
-func ClearFolderEx(folderFullPath string, overtime int) error {
-
-	_, hour, minute, _ := my_util.GetNowTimeString()
-	pathSep := string(os.PathSeparator)
-	files, err := os.ReadDir(folderFullPath)
-	if err != nil {
-		return err
-	}
-	for _, curFile := range files {
-		fullPath := folderFullPath + pathSep + curFile.Name()
-		if curFile.IsDir() {
-
-			parts := strings.Split(curFile.Name(), "-")
-			if len(parts) == 3 {
-				// 基本是符合了,倒是还是需要额外的判断是否时间超过了
-				tmpHourStr := parts[0]
-				tmpMinuteStr := parts[1]
-				tmpHour, err := strconv.Atoi(tmpHourStr)
-				if err != nil {
-					// 如果不符合命名格式,直接删除
-					err = os.RemoveAll(fullPath)
-					if err != nil {
-						return err
-					}
-					continue
-				}
-				tmpMinute, err := strconv.Atoi(tmpMinuteStr)
-				if err != nil {
-					// 如果不符合命名格式,直接删除
-					err = os.RemoveAll(fullPath)
-					if err != nil {
-						return err
-					}
-					continue
-				}
-				// 判断时间
-				if tmpHour != hour {
-					// 如果不符合命名格式,直接删除
-					err = os.RemoveAll(fullPath)
-					if err != nil {
-						return err
-					}
-					continue
-				}
-				// 超过 5 min
-				if minute-overtime > tmpMinute {
-					// 如果不符合命名格式,直接删除
-					err = os.RemoveAll(fullPath)
-					if err != nil {
-						return err
-					}
-					continue
-				}
-			} else {
-				// 如果不符合命名格式,直接删除
-				err = os.RemoveAll(fullPath)
-				if err != nil {
-					return err
-				}
-			}
-		} else {
-			// 这里就是文件了
-			err = os.Remove(fullPath)
-			if err != nil {
-				return err
-			}
-		}
-	}
-
-	return nil
-}
-
 // GetConfigRootDirFPath 获取 Config 的根目录,不同系统不一样
 func GetConfigRootDirFPath() string {
 
@@ -362,7 +285,7 @@ func ClearIdleSubFixCacheFolder(rootSubFixCacheFolder string, outOfDate time.Dur
 			if i == 0 {
 				maxAccessTime = accessTime
 			}
-			if my_util.Time2SecondNumber(accessTime) > my_util.Time2SecondNumber(maxAccessTime) {
+			if Time2SecondNumber(accessTime) > Time2SecondNumber(maxAccessTime) {
 				maxAccessTime = accessTime
 			}
 		}

+ 1 - 1
internal/pkg/folder_helper/folder_test.go → internal/pkg/my_util/folder_test.go

@@ -1,4 +1,4 @@
-package folder_helper
+package my_util
 
 import (
 	"testing"

+ 2 - 2
internal/pkg/rod_helper/rodHelper.go

@@ -4,8 +4,8 @@ import (
 	"context"
 	_ "embed"
 	"errors"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg/folder_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/random_useragent"
 	"github.com/go-rod/rod"
 	"github.com/go-rod/rod/lib/launcher"
@@ -173,7 +173,7 @@ func releaseAdblock() (string, error) {
 	}
 	desPath := filepath.Join(adblockFolderPath, "RunAdblock")
 	// 清理之前缓存的信息
-	_ = folder_helper.ClearFolder(desPath)
+	_ = my_util.ClearFolder(desPath)
 	// 具体把 adblock zip 解压下载到哪里
 	outZipFileFPath := filepath.Join(adblockFolderPath, "adblock.zip")
 	adblockZipFile, err := os.Create(outZipFileFPath)

+ 2 - 3
internal/pkg/sub_helper/sub_helper.go

@@ -5,7 +5,6 @@ import (
 	"github.com/allanpk716/ChineseSubFinder/internal/common"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/archive_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/decode"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg/folder_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/language"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
@@ -28,7 +27,7 @@ func OrganizeDlSubFiles(tmpFolderName string, subInfos []supplier.SubInfo) (map[
 	// 缓存列表,整理后的字幕列表
 	// SxEx - []string 字幕的路径
 	var siteSubInfoDict = make(map[string][]string)
-	tmpFolderFullPath, err := folder_helper.GetTmpFolderByName(tmpFolderName)
+	tmpFolderFullPath, err := my_util.GetTmpFolderByName(tmpFolderName)
 	if err != nil {
 		return nil, err
 	}
@@ -349,7 +348,7 @@ func SearchVideoMatchSubFileAndRemoveExtMark(oneVideoFullPath string) error {
 // DeleteOneSeasonSubCacheFolder 删除一个连续剧中的所有一季字幕的缓存文件夹
 func DeleteOneSeasonSubCacheFolder(seriesDir string) error {
 
-	debugFolderByName, err := folder_helper.GetDebugFolderByName([]string{filepath.Base(seriesDir)})
+	debugFolderByName, err := my_util.GetDebugFolderByName([]string{filepath.Base(seriesDir)})
 	if err != nil {
 		return err
 	}

+ 2 - 3
internal/pkg/sub_helper/sub_helper_test.go

@@ -4,7 +4,6 @@ import (
 	"fmt"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/ass"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/srt"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg/folder_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_parser_hub"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/unit_test_helper"
@@ -16,11 +15,11 @@ func TestDeleteOneSeasonSubCacheFolder(t *testing.T) {
 	const testSerName = "XXX"
 	const needDelFolderName = "Sub_S1E0"
 	testRootDir := unit_test_helper.GetTestDataResourceRootPath([]string{"sub_helper", "org", needDelFolderName}, 4, false)
-	desSerFullPath, err := folder_helper.GetDebugFolderByName([]string{testSerName})
+	desSerFullPath, err := my_util.GetDebugFolderByName([]string{testSerName})
 	if err != nil {
 		t.Fatal(err)
 	}
-	desSeasonFullPath, err := folder_helper.GetDebugFolderByName([]string{testSerName, filepath.Base(testRootDir)})
+	desSeasonFullPath, err := my_util.GetDebugFolderByName([]string{testSerName, filepath.Base(testRootDir)})
 	if err != nil {
 		t.Fatal(err)
 	}

+ 162 - 7
internal/pkg/unit_test_helper/unit_test_helper.go

@@ -1,12 +1,13 @@
 package unit_test_helper
 
 import (
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg/folder_helper"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
+	"fmt"
 	"io"
 	"os"
 	"path/filepath"
 	"strconv"
+	"strings"
+	"time"
 )
 
 // GetTestDataResourceRootPath 向上返回几层就能够到 ChineseSubFinder-TestData 同级目录,然后进入其中的 resourceFolderName 资源文件夹中
@@ -27,7 +28,7 @@ func GetTestDataResourceRootPath(resourceFolderNames []string, goBackTimes int,
 	if userCopyData == true {
 		// 想要 copy org 中的数据到 test 中去处理
 		orgDir := filepath.Join(outPath, "org")
-		if my_util.IsDir(orgDir) == false {
+		if IsDir(orgDir) == false {
 			// 如果没有发现 org 文件夹,就返回之前的路径即可
 			return outPath
 		}
@@ -143,13 +144,13 @@ func copyTestData(srcDir string) (string, error) {
 
 	// 因为会出现,批量测试的需求,那么如果每次都进行一次清理,那么就会导致之前创建的被清理掉,测试用例失败
 	// 可以简单的按时间来判断,如果当前时间与以及存在文件夹名称相差在 5min,那么就清理掉
-	addString, _, _, _ := my_util.GetNowTimeString()
+	addString, _, _, _ := GetNowTimeString()
 	// 测试数据的文件夹
 	orgDir := filepath.Join(srcDir, "org")
 	testDir := filepath.Join(srcDir, "test")
 
-	if my_util.IsDir(testDir) == true {
-		err := folder_helper.ClearFolderEx(testDir, 10)
+	if IsDir(testDir) == true {
+		err := ClearFolderEx(testDir, 10)
 		if err != nil {
 			return "", err
 		}
@@ -157,12 +158,166 @@ func copyTestData(srcDir string) (string, error) {
 
 	// 多加一层,这样在批量测试的时候才不会出错
 	testDirEx := filepath.Join(testDir, addString)
-	err := my_util.CopyDir(orgDir, testDirEx)
+	err := CopyDir(orgDir, testDirEx)
 	if err != nil {
 		return "", err
 	}
 	return testDirEx, nil
 }
 
+// IsDir 存在且是文件夹
+func IsDir(path string) bool {
+	s, err := os.Stat(path)
+	if err != nil {
+		return false
+	}
+	return s.IsDir()
+}
+
+// CopyFile copies a single file from src to dst
+func CopyFile(src, dst string) error {
+	var err error
+	var srcFd *os.File
+	var dstFd *os.File
+	var srcInfo os.FileInfo
+
+	if srcFd, err = os.Open(src); err != nil {
+		return err
+	}
+	defer func() {
+		_ = srcFd.Close()
+	}()
+
+	if dstFd, err = os.Create(dst); err != nil {
+		return err
+	}
+	defer func() {
+		_ = dstFd.Close()
+	}()
+
+	if _, err = io.Copy(dstFd, srcFd); err != nil {
+		return err
+	}
+	if srcInfo, err = os.Stat(src); err != nil {
+		return err
+	}
+	return os.Chmod(dst, srcInfo.Mode())
+}
+
+// CopyDir copies a whole directory recursively
+func CopyDir(src string, dst string) error {
+	var err error
+	var fds []os.DirEntry
+	var srcInfo os.FileInfo
+
+	if srcInfo, err = os.Stat(src); err != nil {
+		return err
+	}
+
+	if err = os.MkdirAll(dst, srcInfo.Mode()); err != nil {
+		return err
+	}
+
+	if fds, err = os.ReadDir(src); err != nil {
+		return err
+	}
+	for _, fd := range fds {
+		srcfp := filepath.Join(src, fd.Name())
+		dstfp := filepath.Join(dst, fd.Name())
+
+		if fd.IsDir() {
+			if err = CopyDir(srcfp, dstfp); err != nil {
+				fmt.Println(err)
+			}
+		} else {
+			if err = CopyFile(srcfp, dstfp); err != nil {
+				fmt.Println(err)
+			}
+		}
+	}
+	return nil
+}
+
+// GetNowTimeString 获取当前的时间,没有秒
+func GetNowTimeString() (string, int, int, int) {
+	nowTime := time.Now()
+	addString := fmt.Sprintf("%d-%d-%d", nowTime.Hour(), nowTime.Minute(), nowTime.Nanosecond())
+	return addString, nowTime.Hour(), nowTime.Minute(), nowTime.Nanosecond()
+}
+
+// ClearFolderEx 清空文件夹,文件夹名称有特殊之处,Hour-min-Nanosecond 的命名方式
+// 如果调用的时候,已存在的文件夹的时间 min < 5 那么则清理
+func ClearFolderEx(folderFullPath string, overtime int) error {
+
+	_, hour, minute, _ := GetNowTimeString()
+	pathSep := string(os.PathSeparator)
+	files, err := os.ReadDir(folderFullPath)
+	if err != nil {
+		return err
+	}
+	for _, curFile := range files {
+		fullPath := folderFullPath + pathSep + curFile.Name()
+		if curFile.IsDir() {
+
+			parts := strings.Split(curFile.Name(), "-")
+			if len(parts) == 3 {
+				// 基本是符合了,倒是还是需要额外的判断是否时间超过了
+				tmpHourStr := parts[0]
+				tmpMinuteStr := parts[1]
+				tmpHour, err := strconv.Atoi(tmpHourStr)
+				if err != nil {
+					// 如果不符合命名格式,直接删除
+					err = os.RemoveAll(fullPath)
+					if err != nil {
+						return err
+					}
+					continue
+				}
+				tmpMinute, err := strconv.Atoi(tmpMinuteStr)
+				if err != nil {
+					// 如果不符合命名格式,直接删除
+					err = os.RemoveAll(fullPath)
+					if err != nil {
+						return err
+					}
+					continue
+				}
+				// 判断时间
+				if tmpHour != hour {
+					// 如果不符合命名格式,直接删除
+					err = os.RemoveAll(fullPath)
+					if err != nil {
+						return err
+					}
+					continue
+				}
+				// 超过 5 min
+				if minute-overtime > tmpMinute {
+					// 如果不符合命名格式,直接删除
+					err = os.RemoveAll(fullPath)
+					if err != nil {
+						return err
+					}
+					continue
+				}
+			} else {
+				// 如果不符合命名格式,直接删除
+				err = os.RemoveAll(fullPath)
+				if err != nil {
+					return err
+				}
+			}
+		} else {
+			// 这里就是文件了
+			err = os.Remove(fullPath)
+			if err != nil {
+				return err
+			}
+		}
+	}
+
+	return nil
+}
+
 const oneBackTime = "../"
 const testResourceProjectName = "ChineseSubFinder-TestData"