github.com/xraypb/Xray-core@v1.8.1/transport/internet/header_test.go (about)

     1  package internet_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/xraypb/Xray-core/common"
     7  	. "github.com/xraypb/Xray-core/transport/internet"
     8  	"github.com/xraypb/Xray-core/transport/internet/headers/noop"
     9  	"github.com/xraypb/Xray-core/transport/internet/headers/srtp"
    10  	"github.com/xraypb/Xray-core/transport/internet/headers/utp"
    11  	"github.com/xraypb/Xray-core/transport/internet/headers/wechat"
    12  	"github.com/xraypb/Xray-core/transport/internet/headers/wireguard"
    13  )
    14  
    15  func TestAllHeadersLoadable(t *testing.T) {
    16  	testCases := []struct {
    17  		Input interface{}
    18  		Size  int32
    19  	}{
    20  		{
    21  			Input: new(noop.Config),
    22  			Size:  0,
    23  		},
    24  		{
    25  			Input: new(srtp.Config),
    26  			Size:  4,
    27  		},
    28  		{
    29  			Input: new(utp.Config),
    30  			Size:  4,
    31  		},
    32  		{
    33  			Input: new(wechat.VideoConfig),
    34  			Size:  13,
    35  		},
    36  		{
    37  			Input: new(wireguard.WireguardConfig),
    38  			Size:  4,
    39  		},
    40  	}
    41  
    42  	for _, testCase := range testCases {
    43  		header, err := CreatePacketHeader(testCase.Input)
    44  		common.Must(err)
    45  		if header.Size() != testCase.Size {
    46  			t.Error("expected size ", testCase.Size, " but got ", header.Size())
    47  		}
    48  	}
    49  }