Files
huangguo_server/models/v/vidmod/m3u8sign_test.go
T
rootandClaude Opus 5 8679200f41 Initial commit
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 13:57:10 +08:00

36 lines
1.0 KiB
Go

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)
}
}