hot_fix_001_test.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package hot_fix
  2. import (
  3. "github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
  4. "github.com/allanpk716/ChineseSubFinder/internal/pkg/unit_test_helper"
  5. "path/filepath"
  6. "testing"
  7. )
  8. func TestHotFix001_GetKey(t *testing.T) {
  9. hf001 := NewHotFix001([]string{""}, []string{""})
  10. if hf001.GetKey() != "001" {
  11. t.Fatal("GetKey() != 001")
  12. }
  13. }
  14. func TestHotFix001_Process(t *testing.T) {
  15. testDataPath := unit_test_helper.GetTestDataResourceRootPath([]string{"hotfix", "001"}, 4, true)
  16. movieDir := "movies"
  17. seriesDir := "series"
  18. // 测试文件夹
  19. testMovieDir := filepath.Join(testDataPath, movieDir)
  20. testSeriesDir := filepath.Join(testDataPath, seriesDir)
  21. // 开始修复
  22. hf001 := NewHotFix001([]string{testMovieDir}, []string{testSeriesDir})
  23. outData, err := hf001.Process()
  24. outStruct := outData.(OutStruct001)
  25. if err != nil {
  26. for _, file := range outStruct.ErrFiles {
  27. println("rename error:", file)
  28. }
  29. t.Fatal("Process ", err.Error())
  30. }
  31. if len(outStruct.RenamedFiles) < 1 {
  32. t.Fatal("hf001.Process() not file processed")
  33. }
  34. // 检查修复的结果是否符合预期
  35. var newSubFileNameMap = make(map[string]int)
  36. for i, s := range outStruct.RenamedFiles {
  37. if my_util.IsFile(s) == false {
  38. t.Fatal("renamed file not found:", s)
  39. }
  40. newSubFileNameMap[filepath.Base(s)] = i
  41. }
  42. // 21座桥 (2019) 720p AAC.chs[subhd].ass
  43. // 21座桥 (2019) 720p AAC.chs_en[zimuku].ass
  44. // 无罪之最 - S01E01 - 重建生活.chs[shooter].ass
  45. // 无罪之最 - S01E01 - 重建生活.chs[subhd].ass
  46. // 无罪之最 - S01E01 - 重建生活.chs[zimuku].ass
  47. // Loki - S01E01 - Glorious Purpose WEBDL-1080p Proper.chs_en[zimuku].srt
  48. // Loki - S01E01 - Glorious Purpose WEBDL-1080p Proper.cht_en[shooter].ass
  49. var checkResults = []string{
  50. "21座桥 (2019) 720p AAC.chinese(简,subhd).ass",
  51. "21座桥 (2019) 720p AAC.chinese(简英,zimuku).ass",
  52. "无罪之最 - S01E01 - 重建生活.chinese(简,shooter).ass",
  53. "无罪之最 - S01E01 - 重建生活.chinese(简,subhd).ass",
  54. "无罪之最 - S01E01 - 重建生活.chinese(简,zimuku).ass",
  55. "Loki - S01E01 - Glorious Purpose WEBDL-1080p Proper.chinese(简英,zimuku).srt",
  56. "Loki - S01E01 - Glorious Purpose WEBDL-1080p Proper.chinese(繁英,shooter).ass",
  57. }
  58. if len(outStruct.RenamedFiles) != len(checkResults) {
  59. t.Logf("\n\nnewSubFileName.len %d != checkResults.len %d", len(outStruct.RenamedFiles), len(checkResults))
  60. t.FailNow()
  61. }
  62. for _, result := range checkResults {
  63. _, bok := newSubFileNameMap[result]
  64. if bok == false {
  65. t.Fatal("renamed file name not fit:", result)
  66. }
  67. }
  68. }