123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- package rest_websocket
- import (
- "bytes"
- "io"
- "testing"
- "time"
- "git.ali33.ru/fcg-xvii/go-tools/json"
- "git.ali33.ru/fcg-xvii/rest"
- )
- func TestRequest(t *testing.T) {
- rbuf := make([]byte, 100)
- fTmp := rest.NewReadCloserLen(
- io.NopCloser(bytes.NewReader(rbuf)),
- int64(len(rbuf)),
- )
- req := &rest.RequestStream{
- ID: 10,
- Timeout: time.Now().Add(time.Minute),
- Request: &rest.Request{
- Type: rest.RequestTypeOut,
- Command: "f-command",
- Data: json.Map{
- "one": 1,
- "two": 2,
- },
- Files: rest.RequestFiles{
- "file.txt": fTmp,
- },
- },
- }
- var buf bytes.Buffer
- req.Write(&buf)
- t.Log(buf.Bytes())
- rreq, err := rest.ReadRequestStream(&buf)
- if err != nil {
- t.Log(err.Map().JSONPrettyString())
- }
- t.Log(rreq)
- t.Log(rreq.Files)
- }
- /*
- func TestMessage(t *testing.T) {
- rbuf := make([]byte, 100)
- fTmp := rest.NewReadCloserLen(
- io.NopCloser(bytes.NewReader(rbuf)),
- int64(len(rbuf)),
- )
- mes := NewMessage(
- "okko",
- json.Map{
- "one": 1,
- "two": 2,
- },
- map[string]rest.IReadCloserLen{
- "file.txt": fTmp,
- },
- time.Second,
- rest.RequestTypeMessage,
- )
- var buf bytes.Buffer
- if err := mes.Write(&buf); err != nil {
- t.Fatal(err)
- }
- mes2, err := ReadMessage(&buf)
- if err != nil {
- t.Fatal(err)
- }
- t.Log(mes2)
- t.Log(mes2.files["file.txt"].Len())
- mes2.Close()
- }
- */
|