浏览代码

修复,SearchMatchedSubFileByDir 的 bug

Signed-off-by: allan716 <[email protected]>
allan716 3 年之前
父节点
当前提交
c1832fa4f1

+ 2 - 1
.gitignore

@@ -47,4 +47,5 @@
 /internal/logic/sub_supplier/xunlei/Logs
 
 TestData/*
-TestData/
+TestData/
+/internal/pkg/hot_fix/Logs/*.log

+ 4 - 7
internal/pkg/hot_fix/hot_fix_001_test.go

@@ -2,6 +2,7 @@ package hot_fix
 
 import (
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/unit_test_helper"
 	"path/filepath"
 	"testing"
 )
@@ -14,17 +15,13 @@ func TestHotFix001_GetKey(t *testing.T) {
 }
 
 func TestHotFix001_Process(t *testing.T) {
-	testDataPath := filepath.FromSlash("../../../TestData/hotfix/001")
+	testDataPath := unit_test_helper.GetTestDataResourceRootPath([]string{"hotfix", "001"}, 4, true)
 
 	movieDir := "movies"
 	seriesDir := "series"
-	testRootDir, err := my_util.CopyTestData(testDataPath)
-	if err != nil {
-		t.Fatal(err)
-	}
 	// 测试文件夹
-	testMovieDir := filepath.Join(testRootDir, movieDir)
-	testSeriesDir := filepath.Join(testRootDir, seriesDir)
+	testMovieDir := filepath.Join(testDataPath, movieDir)
+	testSeriesDir := filepath.Join(testDataPath, seriesDir)
 	// 开始修复
 	hf001 := NewHotFix001(testMovieDir, testSeriesDir)
 	outData, err := hf001.Process()

+ 4 - 8
internal/pkg/hot_fix/hot_fix_hub_test.go

@@ -3,7 +3,7 @@ package hot_fix
 import (
 	"github.com/allanpk716/ChineseSubFinder/internal/dao"
 	"github.com/allanpk716/ChineseSubFinder/internal/models"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/unit_test_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/types"
 	"path/filepath"
 	"testing"
@@ -16,16 +16,12 @@ func TestHotFixProcess(t *testing.T) {
 	if err != nil {
 		t.Fatal(err)
 	}
-	testDataPath := filepath.FromSlash("../../../TestData/hotfix/001")
+	testDataPath := unit_test_helper.GetTestDataResourceRootPath([]string{"hotfix", "001"}, 4, true)
 	movieDir := "movies"
 	seriesDir := "series"
-	testRootDir, err := my_util.CopyTestData(testDataPath)
-	if err != nil {
-		t.Fatal(err)
-	}
 	// 测试文件夹
-	testMovieDir := filepath.Join(testRootDir, movieDir)
-	testSeriesDir := filepath.Join(testRootDir, seriesDir)
+	testMovieDir := filepath.Join(testDataPath, movieDir)
+	testSeriesDir := filepath.Join(testDataPath, seriesDir)
 	// 开始修复
 	err = HotFixProcess(types.HotFixParam{
 		MovieRootDir:  testMovieDir,

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

@@ -209,10 +209,10 @@ func SearchMatchedSubFileByDir(dir string) ([]string, error) {
 	}
 	for _, curFile := range files {
 		fullPath := dir + pathSep + curFile.Name()
-		if curFile.IsDir() {
+		if my_util.IsDir(fullPath) == true {
 			// 需要排除 Sub_S1E0、Sub_S2E0 这样的整季的字幕文件夹,这里仅仅是缓存,不会被加载的
 			matched := regex_things.RegOneSeasonSubFolderNameMatch.FindAllStringSubmatch(curFile.Name(), -1)
-			if matched == nil || len(matched) > 0 {
+			if matched != nil && len(matched) > 0 {
 				continue
 			}
 			// 内层的错误就无视了