unarchiveFile_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package archive_helper
  2. import (
  3. "github.com/allanpk716/ChineseSubFinder/internal/pkg"
  4. "path"
  5. "path/filepath"
  6. "strings"
  7. "testing"
  8. )
  9. func TestUnArchiveFile(t *testing.T) {
  10. testDataPath := "../../../TestData/zips"
  11. testRootDir, err := pkg.CopyTestData(testDataPath)
  12. if err != nil {
  13. t.Fatal(err)
  14. }
  15. tetUnArchive(t, testRootDir, "zip.zip")
  16. tetUnArchive(t, testRootDir, "tar.tar")
  17. tetUnArchive(t, testRootDir, "rar.rar")
  18. tetUnArchive(t, testRootDir, "7z.7z")
  19. }
  20. func tetUnArchive(t *testing.T, testRootDir string, missionName string) {
  21. fileFPath := filepath.Join(testRootDir, missionName)
  22. desPath := filepath.Join(testRootDir, strings.ReplaceAll(filepath.Ext(missionName), ".", ""))
  23. err := UnArchiveFile(fileFPath, desPath)
  24. if err != nil {
  25. t.Fatal(err)
  26. }
  27. if pkg.IsFile(filepath.Join(desPath, subASS)) == false {
  28. t.Fatal(missionName, " unArchive failed")
  29. }
  30. if pkg.IsFile(filepath.Join(desPath, subSRT)) == false {
  31. t.Fatal(missionName, " unArchive failed")
  32. }
  33. }
  34. const subASS = "oslo.2021.1080p.web.h264-naisu.繁体&英文.ass"
  35. const subSRT = "oslo.2021.1080p.web.h264-naisu.繁体&英文.srt"