z_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package rest_websocket
  2. import (
  3. "bytes"
  4. "io"
  5. "testing"
  6. "time"
  7. "git.ali33.ru/fcg-xvii/go-tools/json"
  8. "git.ali33.ru/fcg-xvii/rest"
  9. )
  10. func TestRequest(t *testing.T) {
  11. rbuf := make([]byte, 100)
  12. fTmp := rest.NewReadCloserLen(
  13. io.NopCloser(bytes.NewReader(rbuf)),
  14. int64(len(rbuf)),
  15. )
  16. req := &rest.RequestStream{
  17. ID: 10,
  18. Timeout: time.Now().Add(time.Minute),
  19. Request: &rest.Request{
  20. Type: rest.RequestTypeOut,
  21. Command: "f-command",
  22. Data: json.Map{
  23. "one": 1,
  24. "two": 2,
  25. },
  26. Files: rest.RequestFiles{
  27. "file.txt": fTmp,
  28. },
  29. },
  30. }
  31. var buf bytes.Buffer
  32. req.Write(&buf)
  33. t.Log(buf.Bytes())
  34. rreq, err := rest.ReadRequestStream(&buf)
  35. if err != nil {
  36. t.Log(err.Map().JSONPrettyString())
  37. }
  38. t.Log(rreq)
  39. t.Log(rreq.Files)
  40. }
  41. /*
  42. func TestMessage(t *testing.T) {
  43. rbuf := make([]byte, 100)
  44. fTmp := rest.NewReadCloserLen(
  45. io.NopCloser(bytes.NewReader(rbuf)),
  46. int64(len(rbuf)),
  47. )
  48. mes := NewMessage(
  49. "okko",
  50. json.Map{
  51. "one": 1,
  52. "two": 2,
  53. },
  54. map[string]rest.IReadCloserLen{
  55. "file.txt": fTmp,
  56. },
  57. time.Second,
  58. rest.RequestTypeMessage,
  59. )
  60. var buf bytes.Buffer
  61. if err := mes.Write(&buf); err != nil {
  62. t.Fatal(err)
  63. }
  64. mes2, err := ReadMessage(&buf)
  65. if err != nil {
  66. t.Fatal(err)
  67. }
  68. t.Log(mes2)
  69. t.Log(mes2.files["file.txt"].Len())
  70. mes2.Close()
  71. }
  72. */