|
@@ -2,7 +2,10 @@ package unit_test_helper
|
|
|
|
|
|
import (
|
|
|
"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
|
|
|
+ "io"
|
|
|
+ "os"
|
|
|
"path/filepath"
|
|
|
+ "strconv"
|
|
|
)
|
|
|
|
|
|
// GetTestDataResourceRootPath 向上返回几层就能够到 ChineseSubFinder-TestData 同级目录,然后进入其中的 resourceFolderName 资源文件夹中
|
|
@@ -38,6 +41,102 @@ func GetTestDataResourceRootPath(resourceFolderNames []string, goBackTimes int,
|
|
|
return outPath
|
|
|
}
|
|
|
|
|
|
+// GenerateShooterVideoFile 这里为 shooter 的接口专门生成一个视频文件,瑞克和莫蒂 (2013)\Season 5\S05E09 .mkv
|
|
|
+func GenerateShooterVideoFile(videoPartsRootPath string) (string, error) {
|
|
|
+
|
|
|
+ const videoSize int64 = 640302895
|
|
|
+ const videoName = "S05E09.mkv"
|
|
|
+ const ext = ".videoPart"
|
|
|
+ partNames := []string{"4096", "213434298", "426868596", "640294703"}
|
|
|
+
|
|
|
+ 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
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ 一共有 4 个检测点
|
|
|
+ */
|
|
|
+ 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
|
|
|
+}
|
|
|
+
|
|
|
+// 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) {
|
|
|
// 测试数据的文件夹
|