golang-im聊天
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

logic_int_test.go 2.6 KiB

2 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package api
  2. import (
  3. "context"
  4. "fmt"
  5. "gim/pkg/logger"
  6. "gim/pkg/pb"
  7. "gim/pkg/util"
  8. "testing"
  9. "time"
  10. "google.golang.org/protobuf/proto"
  11. "google.golang.org/grpc"
  12. "google.golang.org/grpc/metadata"
  13. )
  14. func getLogicIntClient() pb.LogicIntClient {
  15. conn, err := grpc.Dial("111.229.238.28:50000", grpc.WithInsecure())
  16. if err != nil {
  17. logger.Sugar.Error(err)
  18. return nil
  19. }
  20. return pb.NewLogicIntClient(conn)
  21. }
  22. func TestLogicIntServer_SignIn(t *testing.T) {
  23. token := ""
  24. resp, err := getLogicIntClient().ConnSignIn(context.TODO(),
  25. &pb.ConnSignInReq{
  26. DeviceId: 1,
  27. UserId: 1,
  28. Token: token,
  29. ConnAddr: "127.0.0.1:5000",
  30. })
  31. if err != nil {
  32. logger.Sugar.Error(err)
  33. return
  34. }
  35. logger.Sugar.Info(resp)
  36. }
  37. func TestLogicIntServer_Sync(t *testing.T) {
  38. resp, err := getLogicIntClient().Sync(metadata.NewOutgoingContext(context.TODO(), metadata.Pairs("key", "val")),
  39. &pb.SyncReq{
  40. UserId: 1,
  41. DeviceId: 1,
  42. Seq: 0,
  43. })
  44. if err != nil {
  45. logger.Sugar.Error(err)
  46. return
  47. }
  48. logger.Sugar.Info(resp)
  49. }
  50. func TestLogicIntServer_MessageACK(t *testing.T) {
  51. resp, err := getLogicIntClient().MessageACK(metadata.NewOutgoingContext(context.TODO(), metadata.Pairs("key", "val")),
  52. &pb.MessageACKReq{
  53. UserId: 1,
  54. DeviceId: 1,
  55. DeviceAck: 1,
  56. ReceiveTime: 1,
  57. })
  58. if err != nil {
  59. logger.Sugar.Error(err)
  60. return
  61. }
  62. logger.Sugar.Info(resp)
  63. }
  64. func TestLogicIntServer_Offline(t *testing.T) {
  65. resp, err := getLogicIntClient().Offline(metadata.NewOutgoingContext(context.TODO(), metadata.Pairs("key", "val")),
  66. &pb.OfflineReq{
  67. UserId: 1,
  68. DeviceId: 1,
  69. })
  70. if err != nil {
  71. logger.Sugar.Error(err)
  72. return
  73. }
  74. logger.Sugar.Info(resp)
  75. }
  76. func TestLogicIntServer_PushRoom(t *testing.T) {
  77. buf, err := proto.Marshal(&pb.Text{
  78. Text: "hello alber ",
  79. })
  80. if err != nil {
  81. fmt.Println(err)
  82. return
  83. }
  84. resp, err := getLogicIntClient().PushRoom(getCtx(),
  85. &pb.PushRoomReq{
  86. RoomId: 1,
  87. MessageType: pb.MessageType_MT_TEXT,
  88. MessageContent: buf,
  89. SendTime: util.UnixMilliTime(time.Now()),
  90. IsPersist: true,
  91. })
  92. if err != nil {
  93. fmt.Println(err)
  94. return
  95. }
  96. fmt.Printf("%+v\n", resp)
  97. }
  98. func TestLogicIntServer_PushAll(t *testing.T) {
  99. buf, err := proto.Marshal(&pb.Text{
  100. Text: "hello alber ",
  101. })
  102. if err != nil {
  103. fmt.Println(err)
  104. return
  105. }
  106. resp, err := getLogicIntClient().PushAll(getCtx(),
  107. &pb.PushAllReq{
  108. MessageType: pb.MessageType_MT_TEXT,
  109. MessageContent: buf,
  110. SendTime: util.UnixMilliTime(time.Now()),
  111. })
  112. if err != nil {
  113. fmt.Println(err)
  114. return
  115. }
  116. fmt.Printf("%+v\n", resp)
  117. }