fox/processor/processor_test.go

29 lines
660 B
Go
Raw Normal View History

2025-05-27 00:18:59 +08:00
package processor
import (
"fmt"
2025-05-27 00:23:46 +08:00
"github.com/fox/fox/processor/pb"
2025-05-27 00:18:59 +08:00
"github.com/golang/protobuf/proto"
"testing"
)
2025-05-27 00:23:46 +08:00
func onChat(userId int64, req *pb.InternalMsg) {
2025-05-27 00:18:59 +08:00
_ = userId
fmt.Println("onChat", string(req.Msg))
}
func TestProcessor(t *testing.T) {
p := NewProcessor()
p.RegisterMessages(RegisterMetas{
2025-05-27 00:23:46 +08:00
pb.MsgId_Internal: {pb.InternalMsg{}, onChat},
2025-05-27 00:18:59 +08:00
})
2025-05-27 00:23:46 +08:00
tmp := &pb.InternalMsg{UserId: 1, ConnId: 1, MsgId: int32(pb.MsgId_Internal), Msg: []byte("hello world")}
2025-05-27 00:18:59 +08:00
data, _ := proto.Marshal(tmp)
2025-05-27 00:23:46 +08:00
req, _ := p.Unmarshal(int32(pb.MsgId_Internal), data)
if err := p.Dispatch(int32(pb.MsgId_Internal), int64(1), req); err != nil {
2025-05-27 00:18:59 +08:00
t.Error(err)
}
}