Browse Source

调整 xunlei 下载器单元测试为生成的视频文件

Signed-off-by: 716 <[email protected]>
716 3 years ago
parent
commit
06b210dc9c

+ 15 - 2
internal/logic/sub_supplier/xunlei/xunlei_test.go

@@ -1,7 +1,9 @@
 package xunlei
 
 import (
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/unit_test_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/types"
+	"path/filepath"
 	"testing"
 )
 
@@ -13,9 +15,20 @@ func TestGetList(t *testing.T) {
 	//movie1 := "X:\\电影\\机动战士Z高达:星之继承者 (2005)\\机动战士Z高达:星之继承者 (2005) 1080p TrueHD.mkv"
 	//movie1 := "X:\\连续剧\\The Bad Batch\\Season 1\\The Bad Batch - S01E01 - Aftermath WEBDL-1080p.mkv"
 	//movie1 := "X:\\连续剧\\黄石 (2018)\\Season 4\\Yellowstone (2018) - S04E05 - Under a Blanket of Red WEBDL-2160p.mkv"
-	movie1 := "X:\\动漫\\碧蓝之海 (2018)\\Season 1\\碧蓝之海 - S01E01 - [UHA-WINGS][Grand Blue][01][BDRIP 1920x1080 x264 FLACx2].mkv"
+	//movie1 := "X:\\动漫\\碧蓝之海 (2018)\\Season 1\\碧蓝之海 - S01E01 - [UHA-WINGS][Grand Blue][01][BDRIP 1920x1080 x264 FLACx2].mkv"
+	//movie1 := "X:\\连续剧\\瑞克和莫蒂 (2013)\\Season 5\\Rick and Morty - S05E01 - Mort Dinner Rick Andre WEBDL-1080p.mkv"
+	//movie1 := "X:\\电影\\手机 (2003)\\手机 (2003) 720p Cooker.rmvb"
+
+	rootDir := unit_test_helper.GetTestDataResourceRootPath([]string{"sub_spplier"}, 5, true)
+	rootDir = filepath.Join(rootDir, "xunlei")
+
+	gVideoFPath, err := unit_test_helper.GenerateXunleiVideoFile(rootDir)
+	if err != nil {
+		t.Fatal(err)
+	}
+
 	xunlie := NewSupplier(types.ReqParam{Topic: 3})
-	outList, err := xunlie.getSubListFromFile(movie1)
+	outList, err := xunlie.getSubListFromFile(gVideoFPath)
 	if err != nil {
 		t.Error(err)
 	}

+ 48 - 0
internal/pkg/unit_test_helper/unit_test_helper.go

@@ -89,6 +89,54 @@ func GenerateShooterVideoFile(videoPartsRootPath string) (string, error) {
 	return outVideoFPath, nil
 }
 
+// GenerateXunleiVideoFile 这里为 xunlei 的接口专门生成一个视频文件,手机 (2003) 720p Cooker.rmvb
+func GenerateXunleiVideoFile(videoPartsRootPath string) (string, error) {
+
+	const videoSize int64 = 640302895
+	const videoName = "手机 (2003) 720p Cooker.rmvb"
+	const ext = ".videoPart"
+	partNames := []string{"0", "311177499", "933512018"}
+
+	outVideoFPath := filepath.Join(videoPartsRootPath, videoName)
+
+	f, err := os.Create(outVideoFPath)
+	if err != nil {
+		return "", err
+	}
+	defer func() {
+		_ = f.Close()
+	}()
+
+	if err := f.Truncate(videoSize); err != nil {
+		return "", err
+	}
+
+	/*
+		一共有 3 个检测点
+	*/
+	for _, name := range partNames {
+
+		partF, err := os.Open(filepath.Join(videoPartsRootPath, name+ext))
+		if err != nil {
+			return "", err
+		}
+		partAll, err := io.ReadAll(partF)
+		if err != nil {
+			return "", err
+		}
+		int64Numb, err := strconv.ParseInt(name, 10, 64)
+		if err != nil {
+			return "", err
+		}
+		_, err = f.WriteAt(partAll, int64Numb)
+		if err != nil {
+			return "", err
+		}
+	}
+
+	return outVideoFPath, nil
+}
+
 // copyTestData 单元测试前把测试的数据 copy 一份出来操作,src 目录中默认应该有一个 org 原始数据文件夹,然后需要复制一份 test 文件夹出来
 func copyTestData(srcDir string) (string, error) {
 	// 测试数据的文件夹