add go unit test

send status messages when tvshow reindexing
This commit is contained in:
lukas 2021-05-01 16:25:32 +02:00
parent d6fd2cbd9c
commit 5295f0b182
3 changed files with 20 additions and 10 deletions

View File

@ -2,7 +2,6 @@ package videoparser
import (
"fmt"
"openmediacenter/apiGo/api/types"
"openmediacenter/apiGo/database"
"openmediacenter/apiGo/videoparser/tmdb"
"regexp"
@ -10,17 +9,19 @@ import (
"strings"
)
func startTVShowReindex(files []Show, sett types.SettingsType) {
// have fun with db insertions here!
func startTVShowReindex(files []Show) {
allTVshows := getAllTVShows()
for _, file := range files {
// insert new TVShow entry if not existing.
insertShowIfNotExisting(file, allTVshows)
AppendMessage("Processing show: " + file.Name)
insertEpisodesIfNotExisting(file)
}
AppendMessage("reindex finished successfully!")
SendEvent("stop")
}
func insertEpisodesIfNotExisting(show Show) {
@ -44,11 +45,9 @@ func insertEpisodesIfNotExisting(show Show) {
diff := difference(show.files, dbepisodes)
for _, s := range diff {
AppendMessage("Adding Episode: " + s)
insertEpisode(s, show.Name)
}
fmt.Println("diff is...")
fmt.Println(len(diff))
}
func insertEpisode(path string, ShowName string) {

View File

@ -0,0 +1,13 @@
package videoparser
import "testing"
func TestDifference(t *testing.T) {
arr1 := []string{"test1", "test2", "test3"}
arr2 := []string{"test1", "test3"}
res := difference(arr1, arr2)
if len(res) != 1 || res[0] != "test2" {
t.Errorf("wrong difference result.")
}
}

View File

@ -112,15 +112,13 @@ func StartTVShowReindex() {
}
}
fmt.Println(files)
if err != nil {
fmt.Println(err.Error())
}
// start reindex process
AppendMessage("Starting Reindexing!")
go startTVShowReindex(files, mSettings)
go startTVShowReindex(files)
}
func StartCleanup() {