From 9561301fea0b5670bba59884e07239143b6085aa Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Sat, 16 Dec 2017 23:31:05 +0100 Subject: [PATCH] update headers test cases --- transport/internet/headers/srtp/srtp.go | 5 +++-- transport/internet/headers/srtp/srtp_test.go | 6 +++++- transport/internet/headers/utp/utp.go | 6 +++--- transport/internet/headers/utp/utp_test.go | 6 +++++- transport/internet/headers/wechat/wechat.go | 1 + transport/internet/headers/wechat/wechat_test.go | 6 +++++- 6 files changed, 22 insertions(+), 8 deletions(-) diff --git a/transport/internet/headers/srtp/srtp.go b/transport/internet/headers/srtp/srtp.go index 8a40d9c8..69e08b4b 100644 --- a/transport/internet/headers/srtp/srtp.go +++ b/transport/internet/headers/srtp/srtp.go @@ -25,7 +25,8 @@ func (s *SRTP) Write(b []byte) (int, error) { return 4, nil } -func NewSRTP(ctx context.Context, config interface{}) (interface{}, error) { +// New returns a new SRTP instance based on the given config. +func New(ctx context.Context, config interface{}) (interface{}, error) { return &SRTP{ header: 0xB5E8, number: dice.RollUint16(), @@ -33,5 +34,5 @@ func NewSRTP(ctx context.Context, config interface{}) (interface{}, error) { } func init() { - common.Must(common.RegisterConfig((*Config)(nil), NewSRTP)) + common.Must(common.RegisterConfig((*Config)(nil), New)) } diff --git a/transport/internet/headers/srtp/srtp_test.go b/transport/internet/headers/srtp/srtp_test.go index db138fa5..b4f498d8 100644 --- a/transport/internet/headers/srtp/srtp_test.go +++ b/transport/internet/headers/srtp/srtp_test.go @@ -1,6 +1,7 @@ package srtp_test import ( + "context" "testing" "v2ray.com/core/common/buf" @@ -12,7 +13,10 @@ func TestSRTPWrite(t *testing.T) { assert := With(t) content := []byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'} - srtp := SRTP{} + srtpRaw, err := New(context.Background(), &Config{}) + assert(err, IsNil) + + srtp := srtpRaw.(*SRTP) payload := buf.NewLocal(2048) payload.AppendSupplier(srtp.Write) diff --git a/transport/internet/headers/utp/utp.go b/transport/internet/headers/utp/utp.go index 4d8b8189..c76c5fe0 100644 --- a/transport/internet/headers/utp/utp.go +++ b/transport/internet/headers/utp/utp.go @@ -26,8 +26,8 @@ func (u *UTP) Write(b []byte) (int, error) { return 4, nil } -// NewUTP creates a new UTP header for the given config. -func NewUTP(ctx context.Context, config interface{}) (interface{}, error) { +// New creates a new UTP header for the given config. +func New(ctx context.Context, config interface{}) (interface{}, error) { return &UTP{ header: 1, extension: 0, @@ -36,5 +36,5 @@ func NewUTP(ctx context.Context, config interface{}) (interface{}, error) { } func init() { - common.Must(common.RegisterConfig((*Config)(nil), NewUTP)) + common.Must(common.RegisterConfig((*Config)(nil), New)) } diff --git a/transport/internet/headers/utp/utp_test.go b/transport/internet/headers/utp/utp_test.go index eaffb70c..a8b637dc 100644 --- a/transport/internet/headers/utp/utp_test.go +++ b/transport/internet/headers/utp/utp_test.go @@ -1,6 +1,7 @@ package utp_test import ( + "context" "testing" "v2ray.com/core/common/buf" @@ -12,7 +13,10 @@ func TestUTPWrite(t *testing.T) { assert := With(t) content := []byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'} - utp := UTP{} + utpRaw, err := New(context.Background(), &Config{}) + assert(err, IsNil) + + utp := utpRaw.(*UTP) payload := buf.NewLocal(2048) payload.AppendSupplier(utp.Write) diff --git a/transport/internet/headers/wechat/wechat.go b/transport/internet/headers/wechat/wechat.go index ebc62571..2d0473c9 100644 --- a/transport/internet/headers/wechat/wechat.go +++ b/transport/internet/headers/wechat/wechat.go @@ -25,6 +25,7 @@ func (vc *VideoChat) Write(b []byte) (int, error) { return 13, nil } +// NewVideoChat returns a new VideoChat instance based on given config. func NewVideoChat(ctx context.Context, config interface{}) (interface{}, error) { return &VideoChat{ sn: int(dice.RollUint16()), diff --git a/transport/internet/headers/wechat/wechat_test.go b/transport/internet/headers/wechat/wechat_test.go index 9a26ffa4..2afc9466 100644 --- a/transport/internet/headers/wechat/wechat_test.go +++ b/transport/internet/headers/wechat/wechat_test.go @@ -1,6 +1,7 @@ package wechat_test import ( + "context" "testing" "v2ray.com/core/common/buf" @@ -11,7 +12,10 @@ import ( func TestUTPWrite(t *testing.T) { assert := With(t) - video := VideoChat{} + videoRaw, err := NewVideoChat(context.Background(), &VideoConfig{}) + assert(err, IsNil) + + video := videoRaw.(*VideoChat) payload := buf.NewLocal(2048) payload.AppendSupplier(video.Write)