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 5.3 KiB

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