github.com/eagleql/xray-core@v1.4.4/transport/internet/kcp/io_test.go (about)

     1  package kcp_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	. "github.com/eagleql/xray-core/transport/internet/kcp"
     7  )
     8  
     9  func TestKCPPacketReader(t *testing.T) {
    10  	reader := KCPPacketReader{
    11  		Security: &SimpleAuthenticator{},
    12  	}
    13  
    14  	testCases := []struct {
    15  		Input  []byte
    16  		Output []Segment
    17  	}{
    18  		{
    19  			Input:  []byte{},
    20  			Output: nil,
    21  		},
    22  		{
    23  			Input:  []byte{1},
    24  			Output: nil,
    25  		},
    26  	}
    27  
    28  	for _, testCase := range testCases {
    29  		seg := reader.Read(testCase.Input)
    30  		if testCase.Output == nil && seg != nil {
    31  			t.Errorf("Expect nothing returned, but actually %v", seg)
    32  		} else if testCase.Output != nil && seg == nil {
    33  			t.Errorf("Expect some output, but got nil")
    34  		}
    35  	}
    36  }