github.com/xraypb/xray-core@v1.6.6/transport/internet/headers/srtp/srtp_test.go (about)

     1  package srtp_test
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/xraypb/xray-core/common"
     8  	"github.com/xraypb/xray-core/common/buf"
     9  	. "github.com/xraypb/xray-core/transport/internet/headers/srtp"
    10  )
    11  
    12  func TestSRTPWrite(t *testing.T) {
    13  	content := []byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'}
    14  	srtpRaw, err := New(context.Background(), &Config{})
    15  	common.Must(err)
    16  
    17  	srtp := srtpRaw.(*SRTP)
    18  
    19  	payload := buf.New()
    20  	srtp.Serialize(payload.Extend(srtp.Size()))
    21  	payload.Write(content)
    22  
    23  	expectedLen := int32(len(content)) + srtp.Size()
    24  	if payload.Len() != expectedLen {
    25  		t.Error("expected ", expectedLen, " of bytes, but got ", payload.Len())
    26  	}
    27  }