github.com/cloudwego/kitex@v0.9.0/pkg/remote/trans/invoke/conn_extension_test.go (about)

     1  /*
     2   * Copyright 2021 CloudWeGo Authors
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package invoke
    18  
    19  import (
    20  	"context"
    21  	"testing"
    22  
    23  	"github.com/cloudwego/kitex/internal/test"
    24  )
    25  
    26  func Test_ivkConnExtension_NewWriteByteBuffer(t *testing.T) {
    27  	msg := NewMessage(nil, nil)
    28  	msg.GetRequestReaderByteBuffer()
    29  	ext := newIvkConnExtension()
    30  	test.Assert(t, ext.NewWriteByteBuffer(context.Background(), msg, nil) != nil)
    31  }
    32  
    33  func Test_ivkConnExtension_NewReadByteBuffer(t *testing.T) {
    34  	msg := NewMessage(nil, nil)
    35  	msg.GetRequestReaderByteBuffer()
    36  	ext := newIvkConnExtension()
    37  	test.Assert(t, ext.NewReadByteBuffer(context.Background(), msg, nil) == nil)
    38  	msg.SetRequestBytes([]byte{})
    39  	test.Assert(t, ext.NewReadByteBuffer(context.Background(), msg, nil) != nil)
    40  }
    41  
    42  func Test_ivkConnExtension_ReleaseBuffer(t *testing.T) {
    43  	msg := NewMessage(nil, nil)
    44  	msg.GetRequestReaderByteBuffer()
    45  	ext := newIvkConnExtension()
    46  	bufWriter := ext.NewWriteByteBuffer(context.Background(), msg, nil)
    47  	bufWriter.WriteString("any")
    48  	bufWriter.Flush()
    49  	ext.ReleaseBuffer(bufWriter, nil)
    50  	b, err := msg.GetResponseBytes()
    51  	if err != nil {
    52  		t.Fatal(err)
    53  	}
    54  	test.Assert(t, string(b) == "any")
    55  }