Files
gronod 80e01253a2
Build and publish / Test and build (linux) (pull_request) Canceled after 0s
Build and publish / Test and build (windows) (pull_request) Canceled after 0s
Build and publish / Build and publish Docker image (pull_request) Canceled after 0s
Build and publish / Test and build (darwin) (pull_request) Canceled after 40s
Build and publish / Test and build (darwin) (push) Successful in 2m9s
Build and publish / Test and build (linux) (push) Successful in 2m34s
Build and publish / Test and build (windows) (push) Successful in 3m11s
Build and publish / Build and publish Docker image (push) Successful in 1m55s
Fix #10, #27 and #28 from the read-tools sweep
v2 request lists sent the RAML example sort field requestDate; Ombi
looks up RequestedDate and NullReferenceException'd every non-empty
page. Browse now streams TV popular/most-watched payloads and skips
the hydrated seasonRequests graph that blew the 8 MiB read budget.
provider_summary treats an empty upstream body as an empty group_page.
2026-09-19 20:59:57 +01:00

78 lines
2.1 KiB
Go

package tools
import (
"bytes"
"encoding/json"
"strings"
"testing"
)
func TestEmptyCollection(t *testing.T) {
cases := []struct {
in string
want bool
}{
{"", true},
{" \n", true},
{"null", true},
{"[]", true},
{" {}", false},
{`{"providerId":"1"}`, false},
{`[{"id":1}]`, false},
}
for _, c := range cases {
if got := emptyCollection([]byte(c.in)); got != c.want {
t.Errorf("emptyCollection(%q) = %v, want %v", c.in, got, c.want)
}
}
}
func TestDecodeSkimArrayDropsSeasonRequests(t *testing.T) {
body := `[
{"id":1668,"title":"Reacher","seasonRequests":[{"seasonNumber":1,"episodes":[{"episodeNumber":1,"title":"Pilot"}]}]},
{"id":1396,"title":"Breaking Bad"}
]`
o := &op{warn: []string{}}
arr, fail := o.decodeSkimArray(strings.NewReader(body), maxBrowseBody, browseSkipKeys)
if fail != nil {
t.Fatalf("decode failed: %+v", fail.Error)
}
if len(arr) != 2 {
t.Fatalf("len = %d, want 2", len(arr))
}
if _, ok := arr[0]["seasonRequests"]; ok {
t.Errorf("seasonRequests was not skipped: %v", arr[0])
}
if arr[0]["title"] != "Reacher" {
t.Errorf("title = %v", arr[0]["title"])
}
if _, ok := arr[1]["seasonRequests"]; ok {
t.Errorf("second item unexpectedly has seasonRequests")
}
}
func TestDecodeSkimArrayBudget(t *testing.T) {
item := `{"id":1,"title":"x","seasonRequests":[` + strings.Repeat(`{"e":1},`, 100) + `{"e":2}]}`
body := "[" + item + "]"
o := &op{warn: []string{}}
_, fail := o.decodeSkimArray(strings.NewReader(body), 32, browseSkipKeys)
if fail == nil || fail.Error == nil || fail.Error.Code != "UPSTREAM_SCHEMA_MISMATCH" {
t.Fatalf("expected budget mismatch, got %+v", fail)
}
}
func TestSkipJSONValueNested(t *testing.T) {
raw := `{"keep":true,"seasonRequests":{"a":[1,{"b":[2,3]}],"c":"x"},"title":"T"}`
dec := json.NewDecoder(bytes.NewReader([]byte(raw)))
m, err := decodeSkimObject(dec, browseSkipKeys)
if err != nil {
t.Fatal(err)
}
if m["title"] != "T" || m["keep"] != true {
t.Errorf("kept fields = %v", m)
}
if _, ok := m["seasonRequests"]; ok {
t.Errorf("seasonRequests survived skip: %v", m)
}
}