zv_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package example_chat_test
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "git.ali33.ru/fcg-xvii/rest"
  7. "git.ali33.ru/fcg-xvii/rest/example_chat/chat"
  8. ws "git.ali33.ru/fcg-xvii/rest/rest_websocket"
  9. )
  10. func TestChat(t *testing.T) {
  11. addr := "192.168.88.27:40000"
  12. core := chat.New()
  13. server := rest.NewServer(addr, []byte("top-secret"))
  14. if err := server.Listen(time.Second, context.Background()); err != nil {
  15. t.Fatal(err)
  16. }
  17. app := NewApplication(core)
  18. restEngine := ws.New(app, core)
  19. restEngine.Prepare(server, "/ws")
  20. ch := make(chan struct{})
  21. <-ch
  22. //ch := make(chan struct{})
  23. //<-ch
  24. /*
  25. clAddr := "ws://127.0.0.1:40000/ws"
  26. cl, err := ws.NewClient(clAddr)
  27. if err != nil {
  28. t.Fatal(err)
  29. }
  30. t.Log(cl)
  31. mes := &rest.RequestStream{
  32. Timeout: time.Now().Add(time.Second),
  33. Request: &rest.Request{
  34. Type: rest.RequestTypeIn,
  35. Command: "/users/register",
  36. Data: json.Map{
  37. "name": "LETO",
  38. "password": "my-pass-99",
  39. },
  40. },
  41. }
  42. answ, err := cl.SendMessage(mes)
  43. if err != nil {
  44. t.Fatal(err)
  45. }
  46. resp, ok := <-answ
  47. if !ok {
  48. t.Log("answer is not received")
  49. } else {
  50. t.Log("resp", resp.Data)
  51. }
  52. time.Sleep(time.Second * 5)
  53. cl.Close()
  54. */
  55. }