init: hgmj server initial commit

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-10-08 16:50:13 +08:00
co-authored by Claude Opus 4.7
commit 625e89c15d
1870 changed files with 254090 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
package vidmod
import (
"encoding/json"
"strings"
"testing"
)
func TestWatchConsumeReqVideoIDCompatibility(t *testing.T) {
tests := []struct {
body string
want string
}{
{body: `{"videoId":"new-field"}`, want: "new-field"},
{body: `{"vid":"legacy-field"}`, want: "legacy-field"},
{body: `{"videoId":"new-field","vid":"legacy-field"}`, want: "new-field"},
}
for _, tt := range tests {
var req WatchConsumeReq
if err := json.Unmarshal([]byte(tt.body), &req); err != nil {
t.Fatal(err)
}
if got := req.GetVideoID(); got != tt.want {
t.Fatalf("GetVideoID() = %q, want %q", got, tt.want)
}
}
}
func TestWatchConsumeRespJSON(t *testing.T) {
data, err := json.Marshal(WatchConsumeResp{
IsCan: true,
WatchCount: 2,
TotalWatchCount: 3,
Consumed: false,
})
if err != nil {
t.Fatal(err)
}
for _, field := range []string{
`"isCan":true`,
`"watchCount":2`,
`"totalWatchCount":3`,
`"consumed":false`,
} {
if !strings.Contains(string(data), field) {
t.Fatalf("%s missing from response: %s", field, data)
}
}
}