Initial commit

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-15 13:57:10 +08:00
co-authored by Claude Opus 5
commit 8679200f41
1897 changed files with 257900 additions and 0 deletions
@@ -0,0 +1,68 @@
package collectmod
import (
"reflect"
"testing"
"91porn-server/common/constant"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
)
func TestCollectVideoStatusFilterUsesCompoundIndexFields(t *testing.T) {
id1 := primitive.NewObjectID()
id2 := primitive.NewObjectID()
ids := uniqueVideoIDs([]primitive.ObjectID{id1, id2, id1})
filter := collectVideoStatusFilter(123, ids)
if got := filter["uid"]; got != uint64(123) {
t.Fatalf("uid = %#v, want 123", got)
}
typeMatch, ok := filter["type"].(bson.M)
if !ok {
t.Fatalf("type filter = %T, want bson.M", filter["type"])
}
gotTypes, ok := typeMatch["$in"].([]string)
if !ok {
t.Fatalf("type.$in = %T, want []string", typeMatch["$in"])
}
wantTypes := []string{
constant.CollectTypeSP,
constant.CollectTypeShort,
constant.CollectTypeCover,
constant.CollectTypePIC,
constant.CollectTypeSEED_LINK,
constant.CollectTypeAiPlaza,
}
if !reflect.DeepEqual(gotTypes, wantTypes) {
t.Fatalf("type.$in = %#v, want %#v", gotTypes, wantTypes)
}
objMatch, ok := filter["objID"].(bson.M)
if !ok {
t.Fatalf("objID filter = %T, want bson.M", filter["objID"])
}
gotIDs, ok := objMatch["$in"].([]primitive.ObjectID)
if !ok {
t.Fatalf("objID.$in = %T, want []primitive.ObjectID", objMatch["$in"])
}
if wantIDs := []primitive.ObjectID{id1, id2}; !reflect.DeepEqual(gotIDs, wantIDs) {
t.Fatalf("objID.$in = %#v, want %#v", gotIDs, wantIDs)
}
}
func TestIsCollectVideosEmptyIDsReturnsBeforeDatabaseAccess(t *testing.T) {
originalDB := mdb
mdb = nil
t.Cleanup(func() { mdb = originalDB })
got, err := IsCollectVideos(123, nil)
if err != nil {
t.Fatalf("IsCollectVideos() error = %v", err)
}
if len(got) != 0 {
t.Fatalf("IsCollectVideos() = %#v, want empty map", got)
}
}