hot_fix_001_test.go 2.6 KB

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