internal/live_determine_total_test.go
65 lines · 1975 bytes
1 symbol in this file
1package internal
2
3import (
4 "os"
5 "testing"
6)
7
8// Exercises determineProviderTotalEpisodes against the real provider stack for
9// "One Piece" using the app's own Go HTTP client (no browser), to confirm the
10// total is resolved even when individual providers are down or rate-limited.
11func TestLiveDetermineProviderTotalEpisodes(t *testing.T) {
12 if os.Getenv("CURD_LIVE_DETERMINE_TOTAL") == "" {
13 t.Skip("set CURD_LIVE_DETERMINE_TOTAL=1 to run live")
14 }
15 cfg := &CurdConfig{
16 StoragePath: os.ExpandEnv("$HOME/.local/share/curd"),
17 SubOrDub: "sub",
18 Provider: "stacked",
19 TrackingRemote: "myanimelist",
20 }
21 withGlobalConfig(t, cfg)
22
23 anime := &Anime{
24 AnilistId: 21,
25 MalId: 21,
26 TotalEpisodes: 1100,
27 Title: AnimeTitle{English: "One Piece", Romaji: "One Piece", Japanese: "ONE PIECE"},
28 ProviderName: "",
29 ProviderId: "",
30 IsAiring: true,
31 }
32
33 for _, pn := range configuredProviderNames(cfg) {
34 p, err := ProviderByName(pn)
35 if err != nil {
36 t.Logf(" [%s] not configured: %v", pn, err)
37 continue
38 }
39 opts, derr := p.SearchAnime("One Piece", "sub")
40 if derr != nil {
41 t.Logf(" [%s] search ERROR: %v", pn, derr)
42 continue
43 }
44 if len(opts) == 0 {
45 t.Logf(" [%s] search returned no results", pn)
46 continue
47 }
48 best, _ := selectBestProviderSearchResult(opts, anime, "One Piece")
49 total, terr := getProviderTotalEpisodes(p, best.Key, "sub")
50 t.Logf(" [%s] matched Key=%q total=%d err=%v", pn, best.Key, total, terr)
51 }
52
53 total, err := determineProviderTotalEpisodes(cfg, "One Piece", anime, "sub")
54 t.Logf("determineProviderTotalEpisodes -> total=%d err=%v", total, err)
55 if err != nil {
56 t.Fatalf("could not determine total episodes from providers: %v", err)
57 }
58 if total <= 0 {
59 t.Fatalf("got non-positive total %d", total)
60 }
61 if total < 1000 {
62 t.Fatalf("expected a realistic One Piece total >1000, got %d (wrong match or broken ep list)", total)
63 }
64 t.Logf("OK: One Piece total episodes = %d", total)
65}