Browse Source

调整测试用例遇到的问题

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

+ 2 - 2
internal/downloader_test.go

@@ -38,7 +38,7 @@ func TestDownloader_DownloadSub4Series(t *testing.T) {
 	var err error
 	//dirRoot := "X:\\连续剧\\隐秘的角落 (2020)"
 	//dirRoot := "X:\\连续剧\\The Bad Batch"
-	//dirRoot := "X:\\连续剧\\Loki"
+	dirRoot := "X:\\连续剧\\Loki"
 	//dirRoot := "X:\\连续剧\\豪斯医生 (2004)"
 	//dirRoot := "X:\\连续剧\\Why Women Kill"
 	//dirRoot := "X:\\连续剧\\Mare of Easttown"
@@ -46,7 +46,7 @@ func TestDownloader_DownloadSub4Series(t *testing.T) {
 	//dirRoot := "X:\\连续剧\\黑钱胜地 (2017)"
 	//dirRoot := "X:\\连续剧\\黑道家族 (1999)"
 	//dirRoot := "X:\\连续剧\\黑镜 (2011)"
-	dirRoot := "X:\\连续剧\\黄石 (2018)"
+	//dirRoot := "X:\\连续剧\\黄石 (2018)"
 	//dirRoot := "X:\\连续剧\\少年间谍 (2020)"
 
 	config := config.GetConfig()

+ 2 - 3
internal/logic/series_helper/seriesHelper_test.go

@@ -1,14 +1,13 @@
 package series_helper
 
 import (
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/unit_test_helper"
 	"testing"
 )
 
 func TestReadSeriesInfoFromDir(t *testing.T) {
 
-	series := "X:\\连续剧\\杀死伊芙 (2018)"
-	//series := "X:\\连续剧\\Money.Heist"
-
+	series := unit_test_helper.GetTestDataResourceRootPath([]string{"series", "Loki"}, 4, false)
 	seriesInfo, err := ReadSeriesInfoFromDir(series, nil, false)
 	if err != nil {
 		t.Fatal(err)

+ 4 - 6
internal/logic/sub_supplier/shooter/shooter.go

@@ -124,17 +124,15 @@ func (s Supplier) getSubListFromFile(filePath string) ([]supplier.SubInfo, error
 	return outSubInfoList, nil
 }
 
-func (s Supplier) getSubListFromKeyword(keyword string) ([]supplier.SubInfo, error) {
-	panic("not implemented")
-}
-
 func (s Supplier) computeFileHash(filePath string) (string, error) {
 	hash := ""
 	fp, err := os.Open(filePath)
 	if err != nil {
 		return "", err
 	}
-	defer fp.Close()
+	defer func() {
+		_ = fp.Close()
+	}()
 	stat, err := fp.Stat()
 	if err != nil {
 		return "", err
@@ -182,7 +180,7 @@ func (s Supplier) downloadSub4Series(seriesInfo *series.SeriesInfo) ([]supplier.
 			continue
 		}
 		// 需要赋值给字幕结构
-		for i, _ := range one {
+		for i := range one {
 			one[i].Season = episodeInfo.Season
 			one[i].Episode = episodeInfo.Episode
 		}

+ 12 - 17
internal/logic/sub_supplier/subhd/subhd_test.go

@@ -2,8 +2,8 @@ package subhd
 
 import (
 	series_helper2 "github.com/allanpk716/ChineseSubFinder/internal/logic/series_helper"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg/config"
-	"github.com/allanpk716/ChineseSubFinder/internal/types"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/unit_test_helper"
+	"path/filepath"
 	"testing"
 )
 
@@ -11,13 +11,16 @@ func TestSupplier_GetSubListFromFile(t *testing.T) {
 
 	//movie1 := "X:\\电影\\The Devil All the Time (2020)\\The Devil All the Time (2020) WEBDL-1080p.mkv"
 	//movie1 := "X:\\电影\\Luca (2021)\\Luca (2021) WEBDL-1080p.mkv"
-	movie1 := "X:\\电影\\The Boss Baby Family Business (2021)\\The Boss Baby Family Business (2021) WEBDL-1080p.mkv"
+	//movie1 := "X:\\电影\\The Boss Baby Family Business (2021)\\The Boss Baby Family Business (2021) WEBDL-1080p.mkv"
 	//movie1 := "X:\\电影\\Oslo (2021)\\Oslo (2021) WEBDL-1080p.mkv"
 	//movie1 := "X:\\电影\\Spiral From the Book of Saw (2021)\\Spiral From the Book of Saw (2021) WEBDL-1080p.mkv"
 	//movie1 := "X:\\电影\\消失爱人 (2016)\\消失爱人 (2016) 720p AAC.rmvb"
 	//movie1 := "X:\\电影\\机动战士Z高达:星之继承者 (2005)\\机动战士Z高达:星之继承者 (2005) 1080p TrueHD.mkv"
 	//movie1 := "X:\\连续剧\\The Bad Batch\\Season 1\\The Bad Batch - S01E01 - Aftermath WEBDL-1080p.mkv"
-	subhd := NewSupplier(getReqParam())
+
+	rootDir := unit_test_helper.GetTestDataResourceRootPath([]string{"zimuku"}, 5, true)
+	movie1 := filepath.Join(rootDir, "movies", "The Devil All the Time (2020)", "The Devil All the Time (2020) WEBDL-1080p.mkv")
+	subhd := NewSupplier()
 	outList, err := subhd.getSubListFromFile4Movie(movie1)
 	if err != nil {
 		t.Error(err)
@@ -36,17 +39,19 @@ func TestSupplier_GetSubListFromFile(t *testing.T) {
 func TestSupplier_GetSubListFromFile4Series(t *testing.T) {
 
 	//ser := "X:\\连续剧\\The Bad Batch"	// tt12708542
-	ser := "X:\\连续剧\\瑞克和莫蒂 (2013)" //
+	//ser := "X:\\连续剧\\瑞克和莫蒂 (2013)" //
 	//ser := "X:\\连续剧\\杀死伊芙 (2018)"	// tt7016936
 	//ser := "X:\\连续剧\\Money.Heist"
 	//ser := "X:\\连续剧\\黑钱胜地 (2017)"
 
+	rootDir := unit_test_helper.GetTestDataResourceRootPath([]string{"zimuku"}, 5, true)
+	ser := filepath.Join(rootDir, "series", "黄石 (2018)")
 	// 读取本地的视频和字幕信息
 	seriesInfo, err := series_helper2.ReadSeriesInfoFromDir(ser, nil, false)
 	if err != nil {
 		t.Fatal(err)
 	}
-	s := NewSupplier(getReqParam())
+	s := NewSupplier()
 	outList, err := s.GetSubListFromFile4Series(seriesInfo)
 	if err != nil {
 		t.Fatal(err)
@@ -66,7 +71,7 @@ func TestSupplier_getSubListFromKeyword4Movie(t *testing.T) {
 	//imdbID := "tt6468322" 	// 纸钞屋
 	//imdbID := "tt15299712" // 云南虫谷
 	//imdbID := "tt3626476" // Vacation Friends (2021)
-	subhd := NewSupplier(getReqParam())
+	subhd := NewSupplier()
 	subInfos, err := subhd.getSubListFromKeyword4Movie(imdbID)
 	if err != nil {
 		t.Fatal(err)
@@ -75,13 +80,3 @@ func TestSupplier_getSubListFromKeyword4Movie(t *testing.T) {
 		println(i, sublist.Name, sublist.Ext, sublist.Language.String(), sublist.Score, len(sublist.Data))
 	}
 }
-
-func getReqParam() types.ReqParam {
-
-	config := config.GetConfig()
-	req := types.ReqParam{}
-	if config.UseProxy == true {
-		req.HttpProxy = config.HttpProxy
-	}
-	return req
-}

+ 4 - 8
internal/logic/sub_supplier/xunlei/xunlei.go

@@ -130,10 +130,6 @@ func (s Supplier) getSubListFromFile(filePath string) ([]supplier.SubInfo, error
 	return outSubList, nil
 }
 
-func (s Supplier) getSubListFromKeyword(keyword string) ([]supplier.SubInfo, error) {
-	panic("not implemented")
-}
-
 //getCid 获取指定文件的唯一 cid
 func (s Supplier) getCid(filePath string) (string, error) {
 	hash := ""
@@ -143,7 +139,9 @@ func (s Supplier) getCid(filePath string) (string, error) {
 	if err != nil {
 		return "", err
 	}
-	defer fp.Close()
+	defer func() {
+		_ = fp.Close()
+	}()
 	stat, err := fp.Stat()
 	if err != nil {
 		return "", err
@@ -188,7 +186,7 @@ func (s Supplier) downloadSub4Series(seriesInfo *series.SeriesInfo) ([]supplier.
 			continue
 		}
 		// 需要赋值给字幕结构
-		for i, _ := range one {
+		for i := range one {
 			one[i].Season = episodeInfo.Season
 			one[i].Episode = episodeInfo.Episode
 		}
@@ -211,5 +209,3 @@ type SublistXunLei struct {
 type SublistSliceXunLei struct {
 	Sublist []SublistXunLei
 }
-
-const LangUnknow = "未知语言"

+ 4 - 7
internal/logic/sub_timeline_fixer/SubTimelineFixerHelperEx_test.go

@@ -2,6 +2,8 @@ package sub_timeline_fixer
 
 import (
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/config"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/unit_test_helper"
+	"path/filepath"
 	"testing"
 )
 
@@ -14,6 +16,7 @@ func TestSubTimelineFixerHelperEx_Check(t *testing.T) {
 
 func TestSubTimelineFixerHelperEx_Process(t *testing.T) {
 
+	rootDir := unit_test_helper.GetTestDataResourceRootPath([]string{"sub_timeline_fixer"}, 4, true)
 	type args struct {
 		videoFileFullPath string
 		srcSubFPath       string
@@ -26,13 +29,7 @@ func TestSubTimelineFixerHelperEx_Process(t *testing.T) {
 		{
 			name: "Foundation (2021) - S01E09", args: args{
 				videoFileFullPath: "X:\\连续剧\\Foundation (2021)\\Season 1\\Foundation (2021) - S01E09 - The First Crisis WEBDL-1080p.mkv",
-				srcSubFPath:       "C:\\WorkSpace\\Go2Hell\\src\\github.com\\allanpk716\\ChineseSubFinder\\internal\\logic\\sub_timeline_fixer\\CSF-SubFixCache\\Foundation (2021) - S01E09 - The First Crisis WEBDL-1080p\\chinese(简英,zimuku).default.ass"},
-			wantErr: false,
-		},
-		{
-			name: "Foundation (2021) - S01E09", args: args{
-				videoFileFullPath: "X:\\连续剧\\Foundation (2021)\\Season 1\\Foundation (2021) - S01E09 - The First Crisis WEBDL-1080p.mkv",
-				srcSubFPath:       "C:\\WorkSpace\\Go2Hell\\src\\github.com\\allanpk716\\ChineseSubFinder\\internal\\logic\\sub_timeline_fixer\\CSF-SubFixCache\\Foundation (2021) - S01E09 - The First Crisis WEBDL-1080p\\chinese(简英,zimuku).default.ass"},
+				srcSubFPath:       filepath.Join(rootDir, "Foundation (2021)", "Season 1", "Foundation (2021) - S01E09 - The First Crisis WEBDL-1080p.chinese(简英,zimuku).ass")},
 			wantErr: false,
 		},
 	}