Files
huangguo_server/app/service/mediacontentser/mediacontent_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

69 lines
1.7 KiB
Go

package mediacontentser
import (
"encoding/json"
"testing"
)
func TestMediaContentInfoMarshalH265URL(t *testing.T) {
tests := []struct {
name string
h265URL string
want string
}{
{
name: "resource exists",
h265URL: "https://cdn.example.com/h265/index.m3u8",
want: "https://cdn.example.com/h265/index.m3u8",
},
{
name: "resource missing",
want: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
data, err := json.Marshal(MediaContentInfo{
VideoUrl: "https://cdn.example.com/h264/index.m3u8",
H265Url: tt.h265URL,
})
if err != nil {
t.Fatalf("marshal media content info: %v", err)
}
var response map[string]interface{}
if err := json.Unmarshal(data, &response); err != nil {
t.Fatalf("unmarshal response: %v", err)
}
if response["videoUrl"] != "https://cdn.example.com/h264/index.m3u8" {
t.Fatalf("unexpected H.264 URL: %v", response["videoUrl"])
}
if response["h265Url"] != tt.want {
t.Fatalf("unexpected H.265 URL: %v", response["h265Url"])
}
})
}
}
func TestAppMediaContentMarshalH265URL(t *testing.T) {
data, err := json.Marshal(AppMediaContent{
VideoUrl: "https://cdn.example.com/h264/index.m3u8",
H265Url: "https://cdn.example.com/h265/index.m3u8",
})
if err != nil {
t.Fatalf("marshal app media content: %v", err)
}
var response map[string]interface{}
if err := json.Unmarshal(data, &response); err != nil {
t.Fatalf("unmarshal app media content: %v", err)
}
if response["videoUrl"] != "https://cdn.example.com/h264/index.m3u8" {
t.Fatalf("unexpected H.264 URL: %v", response["videoUrl"])
}
if response["h265Url"] != "https://cdn.example.com/h265/index.m3u8" {
t.Fatalf("unexpected H.265 URL: %v", response["h265Url"])
}
}