Browse Source

fix: change absolute path and log

* add my_util CloseChrome for macOS
* more filepath changing for test files
sdsadfaf 3 years ago
parent
commit
bda1139468

+ 7 - 11
internal/pkg/archive_helper/unarchiveFile_test.go

@@ -3,26 +3,22 @@ package archive_helper
 import (
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"path/filepath"
-	"strings"
 	"testing"
 )
 
 func TestUnArchiveFile(t *testing.T) {
 
-	testDataPath := filepath.FromSlash("../../../TestData/zips")
-	testRootDir, err := my_util.CopyTestData(testDataPath)
-	if err != nil {
-		t.Fatal(err)
-	}
-	testUnArchive(t, testRootDir, "zip.zip")
-	testUnArchive(t, testRootDir, "tar.tar")
-	testUnArchive(t, testRootDir, "rar.rar")
-	testUnArchive(t, testRootDir, "7z.7z")
+	testDataPath := filepath.FromSlash("../../../TestData/archive_helper")
+	// TODO: remove CopyTestData
+	testUnArchive(t, testDataPath, "zip.zip")
+	testUnArchive(t, testDataPath, "tar.tar")
+	testUnArchive(t, testDataPath, "rar.rar")
+	testUnArchive(t, testDataPath, "7z.7z")
 }
 
 func testUnArchive(t *testing.T, testRootDir string, missionName string) {
 	fileFPath := filepath.Join(testRootDir, missionName)
-	desPath := filepath.Join(testRootDir, strings.ReplaceAll(filepath.Ext(missionName), ".", ""))
+	desPath := t.TempDir()
 	err := UnArchiveFile(fileFPath, desPath)
 	if err != nil {
 		t.Fatal(err)

+ 28 - 13
internal/pkg/decode/decode_test.go

@@ -1,15 +1,30 @@
 package decode
 
 import (
-	"fmt"
 	"testing"
     "path/filepath"
 )
 
+func getTestFileDir(testFileName string) (xmlDir string) {
+	if testFileName == "movie.xml" {
+		return filepath.FromSlash("../../../TestData/media/movies/Army of the Dead (2021)/movie.xml")
+	} else if testFileName == "movie.nfo" {
+		return filepath.FromSlash("../../../TestData/media/movies/Army of the Dead (2021)/Army of the Dead (2021).nfo")
+	} else if testFileName == "has_http_address.nfo" {
+		return filepath.FromSlash("../../../TestData/video_info_file/has_http_address.nfo")
+	} else if testFileName == "has_http_address.nfo" {
+		return filepath.FromSlash("../../../TestData/video_info_file/only_http_address.nfo")
+	} else if testFileName == "series.mp4" {
+		return filepath.FromSlash("../../../TestData/media/tv/Friends (1994)/Season 08/Friends (1994) - s08e02.mp4")	
+	}
+
+	return ""
+}
+
 func TestGetImdbAndYearMovieXml(t *testing.T) {
 	wantid := "tt0993840"
 	wantyear := "2021"
-	dirPth := filepath.FromSlash("../../../TestData/video_info_file/movie.xml")
+	dirPth := getTestFileDir("movie.xml")
 	imdbInfo, err := getImdbAndYearMovieXml(dirPth)
 	if err != nil {
 		t.Error(err)
@@ -25,44 +40,44 @@ func TestGetImdbAndYearMovieXml(t *testing.T) {
 func TestGetImdbAndYearNfo(t *testing.T) {
 	wantid := "tt0993840"
 	wantyear := "2021"
-	dirPth := filepath.FromSlash("../../../TestData/video_info_file/Army of the Dead (2021) WEBDL-1080p.nfo")
+	dirPth := getTestFileDir("movie.nfo")
 	imdbInfo, err := getImdbAndYearNfo(dirPth, "movie")
 	if err != nil {
 		t.Fatal(err)
 	}
 	if imdbInfo.ImdbId != wantid {
-		t.Fatal(fmt.Sprintf("id = %v, wantid %v", imdbInfo.ImdbId, wantid))
+		t.Fatalf("\n\nid = %v, wantid %v", imdbInfo.ImdbId, wantid)
 	}
 	if imdbInfo.Year != wantyear {
-		t.Fatal(fmt.Sprintf("year = %v, wantyear %v", imdbInfo.Year, wantyear))
+		t.Fatalf("\n\nyear = %v, wantyear %v", imdbInfo.Year, wantyear)
 	}
 
 	wantid = "tt12801326"
 	wantyear = "2020"
-	dirPth = filepath.FromSlash("../../../TestData/video_info_file/has_http_address.nfo")
+	dirPth =  getTestFileDir("has_http_address.nfo")
 	imdbInfo, err = getImdbAndYearNfo(dirPth, "movie")
 	if err != nil {
 		t.Fatal(err)
 	}
 	if imdbInfo.ImdbId != wantid {
-		t.Fatal(fmt.Sprintf("id = %v, wantid %v", imdbInfo.ImdbId, wantid))
+		t.Fatalf("\n\nid = %v, wantid %v", imdbInfo.ImdbId, wantid)
 	}
 	if imdbInfo.Year != wantyear {
-		t.Fatal(fmt.Sprintf("year = %v, wantyear %v", imdbInfo.Year, wantyear))
+		t.Fatalf("\n\nyear = %v, wantyear %v", imdbInfo.Year, wantyear)
 	}
 
 	wantid = ""
 	wantyear = ""
-	dirPth = filepath.FromSlash("../../../TestData/video_info_file/only_http_address.nfo")
+	dirPth = getTestFileDir("only_http_address.nfo")
 	imdbInfo, err = getImdbAndYearNfo(dirPth, "movie")
 	if err == nil {
-		t.Fatal("need errot")
+		t.Fatal("need error")
 	}
 }
 
 func TestGetVideoInfoFromFileFullPath(t *testing.T) {
 
-	subTitle := filepath.FromSlash("../../../TestData/video_info_file/Friends (1994) - s08e02.mp4")
+	subTitle := getTestFileDir("series.mp4")
 
 	info, modifyTime, err := GetVideoInfoFromFileFullPath(subTitle)
 	if err != nil || info.Season != 8 || info.Episode != 2 {
@@ -103,9 +118,9 @@ func TestGetNumber2int(t *testing.T) {
 	}
 }
 
-func Test_getImdbAndYearNfo(t *testing.T) {
+func TestgetImdbAndYearNfo(t *testing.T) {
 
-	nfoInfo := filepath.FromSlash("../../../TestData/video_info_file/Army of the Dead (2021) WEBDL-1080p.nfo")
+	nfoInfo := getTestFileDir("movie.nfo")
 	nfo, err := getImdbAndYearNfo(nfoInfo, "movie")
     t.Logf("\n\nMovies:\timdbid\tYear\tReleaseDate\n" + 
 			"        %s\t%s\t %s\n", nfo.ImdbId, nfo.Year, nfo.ReleaseDate)

+ 1 - 1
internal/pkg/emby_api/emby_api_test.go

@@ -72,7 +72,7 @@ func TestEmbyHelper_GetUserIdList(t *testing.T) {
 		t.Fatal(err)
 	}
 	for i, item := range userIds.Items {
-		println(i, item.Name, item.Id)
+		t.Logf("\n\n%d  %s  %s", i, item.Name, item.Id)
 	}
 }
 

+ 1 - 0
internal/pkg/my_util/Logs/ChineseSubFinder--2021Len12310000--.log

@@ -0,0 +1 @@
+[ERROR]: 2021-12-31 17:35:50 - CloseChrome exit status 1

+ 1 - 0
internal/pkg/my_util/Logs/ChineseSubFinder.log

@@ -0,0 +1 @@
+ChineseSubFinder--2021Len12310000--.log

+ 5 - 0
internal/pkg/my_util/util.go

@@ -289,6 +289,11 @@ func CloseChrome() {
 		cmdString = "taskkill /F /im notepad.exe"
 		command = exec.Command("cmd.exe", "/c", cmdString)
 	}
+	if sysType == "darwin" {
+		// macOS
+		cmdString = "pkill chrome"
+		command = exec.Command("/bin/sh", "-c", cmdString)
+	}
 	if cmdString == "" || command == nil {
 		log_helper.GetLogger().Errorln("CloseChrome OS:", sysType)
 		return

+ 1 - 0
internal/pkg/my_util/util_test.go

@@ -4,5 +4,6 @@ import "testing"
 
 func TestCloseChrome(t *testing.T) {
 
+	// BUG: will produce Logs under this dir
 	CloseChrome()
 }

+ 1 - 1
internal/pkg/proxy_helper/proxy_helper_test.go

@@ -8,7 +8,7 @@ func TestProxyTest(t *testing.T) {
 	if err != nil {
 		t.Fatal(err)
 	}
-	println("Speed:", gotSpeed, "Status:", gotStatus)
+	t.Logf("Speed: %d Statis: %d", gotSpeed, gotStatus)
 
 	_, _, err = ProxyTest("http:/192.168.1.123:123")
 	if err == nil {

+ 3 - 1
internal/pkg/vad/vad_helper_test.go

@@ -2,12 +2,14 @@ package vad
 
 import (
 	"testing"
+	"path/filepath"
 )
 
 func TestGetVADInfo(t *testing.T) {
 
 	var audioInfo = AudioInfo{
-		FileFullPath: "C:\\Tmp\\Rick and Morty - S05E10\\英_1.pcm",
+		FileFullPath: filepath.FromSlash("../../../TestData/ffmpeg/org/sampleAudio.wav"),
+		// check below accordingly
 		SampleRate:   16000,
 		BitDepth:     16,
 	}

+ 5 - 2
internal/pkg/vosk_api/vosk_client_test.go

@@ -1,9 +1,12 @@
 package vosk_api
 
-import "testing"
+import (
+	"testing"
+	"path/filepath"
+)
 
 func TestGetResult(t *testing.T) {
-	audioFPath := "C:\\Tmp\\audio.wav"
+	audioFPath := filepath.FromSlash("../../../TestData/ffmpeg/org/sampleAudio.wav")
 	err := GetResult(audioFPath)
 	if err != nil {
 		t.Fatal(err)