package rest_websocket

import (
	"bytes"
	"io"
	"testing"
	"time"

	"git.ali33.ru/fcg-xvii/go-tools/json"
	"git.ali33.ru/fcg-xvii/rest"
)

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()
}
