/*
 * Copyright 2022 CloudWeGo Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package fastthrift

import (
	"testing"

	mocks "github.com/cloudwego/kitex/internal/mocks/thrift"
	"github.com/cloudwego/kitex/internal/test"
)

var (
	msgSize = 1024
	keyNum  = 100
)

func newRequest() *mocks.MockReq {
	var strList []string
	for i := 0; i < keyNum; i++ {
		msg := make([]byte, msgSize)
		strList = append(strList, string(msg))
	}

	return &mocks.MockReq{
		StrList: strList,
	}
}

func TestFastThrift(t *testing.T) {
	req1, req2 := newRequest(), &mocks.MockReq{}
	buf := FastMarshal(req1)
	err := FastUnmarshal(buf, req2)
	test.Assert(t, err == nil)
	test.Assert(t, req1.Msg == req2.Msg)
	test.Assert(t, len(req1.StrList) == len(req2.StrList))
}
