golang-im聊天
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

logic_ext_test.go 4.7 KiB

2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. package api
  2. import (
  3. "context"
  4. "fmt"
  5. "gim/pkg/pb"
  6. "gim/pkg/util"
  7. "strconv"
  8. "testing"
  9. "time"
  10. "google.golang.org/grpc"
  11. "google.golang.org/grpc/metadata"
  12. "google.golang.org/protobuf/proto"
  13. )
  14. func getLogicExtClient() pb.LogicExtClient {
  15. conn, err := grpc.Dial("im-rpc-logic.izhyin.com:8003", grpc.WithInsecure())
  16. if err != nil {
  17. fmt.Println(err)
  18. return nil
  19. }
  20. return pb.NewLogicExtClient(conn)
  21. }
  22. // deprecated:
  23. func getCtx() context.Context {
  24. token := "ICXKTELAGMMJYXITSIOUNXFHYMTCWJHMJCIRZLPX"
  25. return metadata.NewOutgoingContext(context.TODO(), metadata.Pairs(
  26. "user_id", "2",
  27. "device_id", "5",
  28. "token", token,
  29. "master_id", "123456",
  30. "request_id", strconv.FormatInt(time.Now().UnixNano(), 10)))
  31. }
  32. func TestLogicExtServer_RegisterDevice(t *testing.T) {
  33. resp, err := getLogicExtClient().RegisterDevice(context.TODO(),
  34. &pb.RegisterDeviceReq{
  35. Type: 1,
  36. Brand: "huawei",
  37. Model: "huawei P30",
  38. SystemVersion: "1.0.0",
  39. SdkVersion: "1.0.0",
  40. })
  41. if err != nil {
  42. fmt.Println(err)
  43. return
  44. }
  45. fmt.Printf("%+v\n", resp)
  46. }
  47. func TestLogicExtServer_SendMessage(t *testing.T) {
  48. buf, err := proto.Marshal(&pb.Text{
  49. Text: "hello world!",
  50. })
  51. if err != nil {
  52. fmt.Println(err)
  53. return
  54. }
  55. var one = string(buf)
  56. fmt.Printf(one)
  57. resp, err := getLogicExtClient().SendMessage(getCtx(),
  58. &pb.SendMessageReq{
  59. ReceiverType: pb.ReceiverType_RT_USER,
  60. ReceiverId: 21,
  61. ToUserIds: nil,
  62. MessageType: pb.MessageType_MT_TEXT,
  63. MessageContent: buf,
  64. IsPersist: true,
  65. SendTime: util.UnixMilliTime(time.Now()),
  66. })
  67. if err != nil {
  68. fmt.Println(err)
  69. return
  70. }
  71. fmt.Printf("%+v\n", resp)
  72. }
  73. func TestLogicExtServer_SendImageMessage(t *testing.T) {
  74. buf, err := proto.Marshal(&pb.Image{
  75. Id: "",
  76. Width: 0,
  77. Height: 0,
  78. Url: "https://img.iplaysoft.com/wp-content/uploads/2019/free-images/free_stock_photo.jpg",
  79. ThumbnailUrl: "",
  80. })
  81. if err != nil {
  82. fmt.Println(err)
  83. return
  84. }
  85. resp, err := getLogicExtClient().SendMessage(getCtx(),
  86. &pb.SendMessageReq{
  87. ReceiverType: pb.ReceiverType_RT_USER,
  88. ReceiverId: 1,
  89. ToUserIds: nil,
  90. MessageType: pb.MessageType_MT_IMAGE,
  91. MessageContent: buf,
  92. IsPersist: true,
  93. SendTime: util.UnixMilliTime(time.Now()),
  94. })
  95. if err != nil {
  96. fmt.Println(err)
  97. return
  98. }
  99. fmt.Printf("%+v\n", resp)
  100. }
  101. func TestLogicExtServer_CreateGroup(t *testing.T) {
  102. resp, err := getLogicExtClient().CreateGroup(getCtx(),
  103. &pb.CreateGroupReq{
  104. Name: "10",
  105. Introduction: "10",
  106. Extra: "10",
  107. })
  108. if err != nil {
  109. fmt.Println(err)
  110. return
  111. }
  112. fmt.Printf("%+v\n", resp)
  113. }
  114. func TestLogicExtServer_UpdateGroup(t *testing.T) {
  115. resp, err := getLogicExtClient().UpdateGroup(getCtx(),
  116. &pb.UpdateGroupReq{
  117. GroupId: 2,
  118. Name: "11",
  119. Introduction: "11",
  120. Extra: "11",
  121. })
  122. if err != nil {
  123. fmt.Println(err)
  124. return
  125. }
  126. fmt.Printf("%+v\n", resp)
  127. }
  128. func TestLogicExtServer_GetGroup(t *testing.T) {
  129. resp, err := getLogicExtClient().GetGroup(getCtx(),
  130. &pb.GetGroupReq{
  131. GroupId: 2,
  132. })
  133. if err != nil {
  134. fmt.Println(err)
  135. return
  136. }
  137. fmt.Printf("%+v\n", resp)
  138. }
  139. func TestLogicExtServer_GetUserGroups(t *testing.T) {
  140. resp, err := getLogicExtClient().GetGroups(getCtx(), &pb.Empty{})
  141. if err != nil {
  142. fmt.Println(err)
  143. return
  144. }
  145. // todo 不能获取用户所在的超大群组
  146. fmt.Printf("%+v\n", resp)
  147. }
  148. func TestLogicExtServer_AddGroupMember(t *testing.T) {
  149. resp, err := getLogicExtClient().AddGroupMembers(getCtx(),
  150. &pb.AddGroupMembersReq{
  151. GroupId: 2,
  152. })
  153. if err != nil {
  154. fmt.Println(err)
  155. return
  156. }
  157. fmt.Printf("%+v\n", resp)
  158. }
  159. func TestLogicExtServer_UpdateGroupMember(t *testing.T) {
  160. resp, err := getLogicExtClient().UpdateGroupMember(getCtx(),
  161. &pb.UpdateGroupMemberReq{
  162. GroupId: 2,
  163. UserId: 3,
  164. Remarks: "2",
  165. Extra: "2",
  166. })
  167. if err != nil {
  168. fmt.Println(err)
  169. return
  170. }
  171. fmt.Printf("%+v\n", resp)
  172. }
  173. func TestLogicExtServer_DeleteGroupMember(t *testing.T) {
  174. resp, err := getLogicExtClient().DeleteGroupMember(getCtx(),
  175. &pb.DeleteGroupMemberReq{
  176. GroupId: 10,
  177. UserId: 1,
  178. })
  179. if err != nil {
  180. fmt.Println(err)
  181. return
  182. }
  183. fmt.Printf("%+v\n", resp)
  184. }
  185. func TestLogicExtServer_GetGroupMembers(t *testing.T) {
  186. resp, err := getLogicExtClient().GetGroupMembers(getCtx(),
  187. &pb.GetGroupMembersReq{
  188. GroupId: 2,
  189. })
  190. if err != nil {
  191. fmt.Println(err)
  192. return
  193. }
  194. fmt.Printf("%+v\n", resp)
  195. }
  196. func TestLogicExtServer_AddFriend(t *testing.T) {
  197. resp, err := getLogicExtClient().AddFriend(getCtx(),
  198. &pb.AddFriendReq{
  199. FriendId: 2,
  200. Remarks: "weihan",
  201. Description: "hello",
  202. })
  203. if err != nil {
  204. fmt.Println(err)
  205. return
  206. }
  207. fmt.Printf("%+v\n", resp)
  208. }