golang-im聊天
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 

60 rindas
1.2 KiB

  1. package api
  2. import (
  3. "context"
  4. "fmt"
  5. "gim/pkg/pb"
  6. "strconv"
  7. "testing"
  8. "time"
  9. "google.golang.org/grpc"
  10. "google.golang.org/grpc/metadata"
  11. )
  12. func getBusinessExtClient() pb.BusinessExtClient {
  13. conn, err := grpc.Dial("im-rpc-business.izhyin.com:8000", grpc.WithInsecure())
  14. if err != nil {
  15. fmt.Println(err)
  16. return nil
  17. }
  18. return pb.NewBusinessExtClient(conn)
  19. }
  20. func getCtx() context.Context {
  21. token := "0"
  22. return metadata.NewOutgoingContext(context.TODO(), metadata.Pairs(
  23. "user_id", "1",
  24. "device_id", "1",
  25. "token", token,
  26. "request_id", strconv.FormatInt(time.Now().UnixNano(), 10)))
  27. }
  28. func TestUserExtServer_SignIn(t *testing.T) {
  29. resp, err := getBusinessExtClient().SignIn(getCtx(), &pb.SignInReq{
  30. PhoneNumber: "18229775311",
  31. DeviceId: 1,
  32. MasterId: 123456,
  33. })
  34. if err != nil {
  35. fmt.Println(err)
  36. }
  37. fmt.Printf("%+v\n", resp)
  38. }
  39. func TestUserExtServer_GetUser(t *testing.T) {
  40. resp, err := getBusinessExtClient().GetUser(getCtx(), &pb.GetUserReq{UserId: 2})
  41. if err != nil {
  42. fmt.Println(err)
  43. }
  44. fmt.Printf("%+v\n", resp)
  45. }
  46. func TestUserExtServer_SearchUser(t *testing.T) {
  47. resp, err := getBusinessExtClient().SearchUser(getCtx(), &pb.SearchUserReq{Key: "18229"})
  48. if err != nil {
  49. fmt.Println(err)
  50. }
  51. fmt.Printf("%+v\n", resp)
  52. }