zv_test.go 1.2 KB

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