1
0

unarchiveFile_test.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package archive_helper
  2. import (
  3. "path/filepath"
  4. "strings"
  5. "testing"
  6. "github.com/ChineseSubFinder/ChineseSubFinder/pkg"
  7. "github.com/ChineseSubFinder/ChineseSubFinder/pkg/unit_test_helper"
  8. )
  9. func TestUnArchiveFile(t *testing.T) {
  10. testRootDir := unit_test_helper.GetTestDataResourceRootPath([]string{"zips"}, 4, true)
  11. testUnArchive(t, testRootDir, "zip.zip")
  12. testUnArchive(t, testRootDir, "tar.tar")
  13. testUnArchive(t, testRootDir, "rar.rar")
  14. testUnArchive(t, testRootDir, "7z.7z")
  15. }
  16. func testUnArchive(t *testing.T, testRootDir string, missionName string) {
  17. fileFPath := filepath.Join(testRootDir, missionName)
  18. desPath := filepath.Join(testRootDir, strings.ReplaceAll(filepath.Ext(missionName), ".", ""))
  19. err := UnArchiveFile(fileFPath, desPath)
  20. if err != nil {
  21. t.Fatal(err)
  22. }
  23. if pkg.IsFile(filepath.Join(desPath, subASS)) == false {
  24. t.Fatal(missionName, " unArchive failed")
  25. }
  26. if pkg.IsFile(filepath.Join(desPath, subSRT)) == false {
  27. t.Fatal(missionName, " unArchive failed")
  28. }
  29. }
  30. const subASS = "oslo.2021.1080p.web.h264-naisu.繁体&英文.ass"
  31. const subSRT = "oslo.2021.1080p.web.h264-naisu.繁体&英文.srt"
  32. func TestUnArchiveFileEx(t *testing.T) {
  33. testRootDir := unit_test_helper.GetTestDataResourceRootPath([]string{"zips"}, 4, true)
  34. type args struct {
  35. fileFullPath string
  36. desRootPath string
  37. }
  38. tests := []struct {
  39. name string
  40. args args
  41. wantErr bool
  42. }{
  43. {
  44. name: "[zimuku]_0_Inside No 9_S7E1.zip", args: args{
  45. fileFullPath: filepath.Join(testRootDir, "[zimuku]_0_Inside No 9_S7E1.zip"),
  46. desRootPath: filepath.Join(testRootDir, "[zimuku]_0_Inside No 9_S7E1"),
  47. }, wantErr: false},
  48. }
  49. for _, tt := range tests {
  50. t.Run(tt.name, func(t *testing.T) {
  51. if err := UnArchiveFileEx(tt.args.fileFullPath, tt.args.desRootPath); (err != nil) != tt.wantErr {
  52. t.Errorf("UnArchiveFileEx() error = %v, wantErr %v", err, tt.wantErr)
  53. }
  54. })
  55. }
  56. }