Files
jellybit/internal/metadata/integration_test.go
T

54 lines
1.5 KiB
Go

package metadata_test
import (
"context"
"os"
"testing"
"time"
"git.vakhrushev.me/av/jellybit/internal/metadata"
)
// TestIntegration_TVDB бьётся в реальный TheTVDB v4. По умолчанию
// пропускается; включается ключом:
//
// TVDB_API_KEY=... go test ./internal/metadata/ -run Integration -v
func TestIntegration_TVDB(t *testing.T) {
key := os.Getenv("TVDB_API_KEY")
if key == "" {
t.Skip("set TVDB_API_KEY to run")
}
c, err := metadata.NewTVDB(metadata.TVDBConfig{APIKey: key, Timeout: 20 * time.Second})
if err != nil {
t.Fatalf("NewTVDB: %v", err)
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
cands, err := c.Search(ctx, metadata.Query{Type: metadata.Series, Title: "Fargo", Year: 2014})
if err != nil {
t.Fatalf("Search: %v", err)
}
t.Logf("candidates (%d):", len(cands))
for i, cd := range cands {
if i >= 5 {
break
}
t.Logf(" id=%s title=%q year=%d", cd.ID, cd.Title, cd.Year)
}
if len(cands) == 0 {
t.Fatal("ожидался хотя бы один кандидат для Fargo")
}
// Берём первого с непустым id и тянем число серий по сезонам.
id := cands[0].ID
counts, err := c.SeasonEpisodeCounts(ctx, id)
if err != nil {
t.Fatalf("SeasonEpisodeCounts(%s): %v", id, err)
}
t.Logf("season episode counts for id=%s: %v", id, counts)
if len(counts) == 0 {
t.Error("ожидались данные о числе серий по сезонам")
}
}