Files
rootandClaude Opus 5 8679200f41 Initial commit
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 13:57:10 +08:00

120 lines
2.9 KiB
Go

package vidhelpser
import (
"encoding/json"
"testing"
"91porn-server/app/appg"
"91porn-server/models/v/locmod"
"91porn-server/models/v/vidmod"
)
func TestH265URLForApp(t *testing.T) {
oldConf := appg.Conf
t.Cleanup(func() {
appg.Conf = oldConf
})
video := &vidmod.VideoModel{H265Url: "https://cdn.example.com/h265/index.m3u8"}
if got := H265URLForApp(nil); got != "" {
t.Fatalf("nil video returned %q", got)
}
appg.Conf = nil
if got := H265URLForApp(video); got != video.H265Url {
t.Fatalf("unconfigured switch returned %q", got)
}
disabled := false
appg.Conf = &appg.GlobalConfig{}
appg.Conf.Hevc.EnableApp = &disabled
if got := H265URLForApp(video); got != "" {
t.Fatalf("disabled switch returned %q", got)
}
enabled := true
appg.Conf.Hevc.EnableApp = &enabled
if got := H265URLForApp(video); got != video.H265Url {
t.Fatalf("enabled switch returned %q", got)
}
}
func TestTransfer2InfoIncludesH265URL(t *testing.T) {
video := &vidmod.VideoModel{
SourceURL: "https://cdn.example.com/h264/index.m3u8",
H265Url: "https://cdn.example.com/h265/index.m3u8",
}
info := transfer2Info(
video,
vidmod.Publisher{},
vidmod.VideoStatus{},
locmod.Location{},
nil,
vidmod.CommentInfo{},
0,
)
data, err := json.Marshal(info)
if err != nil {
t.Fatalf("marshal video info: %v", err)
}
var response map[string]interface{}
if err := json.Unmarshal(data, &response); err != nil {
t.Fatalf("unmarshal video info response: %v", err)
}
if response["sourceURL"] != video.SourceURL {
t.Fatalf("unexpected H.264 URL: %v", response["sourceURL"])
}
if response["h265Url"] != video.H265Url {
t.Fatalf("unexpected H.265 URL: %v", response["h265Url"])
}
}
func TestNewTransfer2InfoIncludesH265URL(t *testing.T) {
video := &vidmod.VideoModel{
SourceURL: "https://cdn.example.com/h264/index.m3u8",
H265Url: "https://cdn.example.com/h265/index.m3u8",
}
info := NewTransfer2Info(
video,
vidmod.Publisher{},
vidmod.VideoStatus{},
nil,
0,
)
data, err := json.Marshal(info)
if err != nil {
t.Fatalf("marshal video info response: %v", err)
}
var response map[string]interface{}
if err := json.Unmarshal(data, &response); err != nil {
t.Fatalf("unmarshal video info response: %v", err)
}
if response["sourceURL"] != video.SourceURL {
t.Fatalf("unexpected H.264 URL: %v", response["sourceURL"])
}
if response["h265Url"] != video.H265Url {
t.Fatalf("unexpected H.265 URL: %v", response["h265Url"])
}
}
func TestToVideoBaseInfoIncludesH265URL(t *testing.T) {
video := &vidmod.VideoModel{
SourceURL: "https://cdn.example.com/h264/index.m3u8",
H265Url: "https://cdn.example.com/h265/index.m3u8",
}
info := ToVideoBaseInfo(video, nil, 0)
if info.SourceURL != video.SourceURL {
t.Fatalf("unexpected H.264 URL: %q", info.SourceURL)
}
if info.H265Url != video.H265Url {
t.Fatalf("unexpected H.265 URL: %q", info.H265Url)
}
}