package vidmod import "testing" // countingSigner 记录被交出的地址字段个数,用于验证各响应体 SignM3u8 的字段枚举是否完整。 type countingSigner struct{ n int } func (c *countingSigner) SignM3u8URL(field *string, playable, preview bool) { c.n++ } func TestVideoInfoOffersThreeFields(t *testing.T) { c := &countingSigner{} (&VideoInfo{}).SignM3u8(c) if c.n != 3 { // sourceURL + h265Url + previewURL t.Fatalf("VideoInfo should offer 3 url fields, got %d", c.n) } } func TestVideoInfoRespOffersTwoFields(t *testing.T) { c := &countingSigner{} (&VideoInfoResp{}).SignM3u8(c) if c.n != 2 { // sourceURL + h265Url(无 previewURL) t.Fatalf("VideoInfoResp should offer 2 url fields, got %d", c.n) } } func TestNilVideosAreSafe(t *testing.T) { c := &countingSigner{} var v *VideoInfo v.SignM3u8(c) // nil 接收者不应 panic SignM3u8Infos(c, []*VideoInfo{nil}) SignM3u8Resps(c, []*VideoInfoResp{nil}) if c.n != 0 { t.Fatalf("nil videos must not offer any field, got %d", c.n) } }