update headers test cases

pull/786/head
Darien Raymond 2017-12-16 23:31:05 +01:00
parent 80e43a6b37
commit 9561301fea
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
6 changed files with 22 additions and 8 deletions

View File

@ -25,7 +25,8 @@ func (s *SRTP) Write(b []byte) (int, error) {
return 4, nil 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{ return &SRTP{
header: 0xB5E8, header: 0xB5E8,
number: dice.RollUint16(), number: dice.RollUint16(),
@ -33,5 +34,5 @@ func NewSRTP(ctx context.Context, config interface{}) (interface{}, error) {
} }
func init() { func init() {
common.Must(common.RegisterConfig((*Config)(nil), NewSRTP)) common.Must(common.RegisterConfig((*Config)(nil), New))
} }

View File

@ -1,6 +1,7 @@
package srtp_test package srtp_test
import ( import (
"context"
"testing" "testing"
"v2ray.com/core/common/buf" "v2ray.com/core/common/buf"
@ -12,7 +13,10 @@ func TestSRTPWrite(t *testing.T) {
assert := With(t) assert := With(t)
content := []byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'} 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 := buf.NewLocal(2048)
payload.AppendSupplier(srtp.Write) payload.AppendSupplier(srtp.Write)

View File

@ -26,8 +26,8 @@ func (u *UTP) Write(b []byte) (int, error) {
return 4, nil return 4, nil
} }
// NewUTP creates a new UTP header for the given config. // New creates a new UTP header for the given config.
func NewUTP(ctx context.Context, config interface{}) (interface{}, error) { func New(ctx context.Context, config interface{}) (interface{}, error) {
return &UTP{ return &UTP{
header: 1, header: 1,
extension: 0, extension: 0,
@ -36,5 +36,5 @@ func NewUTP(ctx context.Context, config interface{}) (interface{}, error) {
} }
func init() { func init() {
common.Must(common.RegisterConfig((*Config)(nil), NewUTP)) common.Must(common.RegisterConfig((*Config)(nil), New))
} }

View File

@ -1,6 +1,7 @@
package utp_test package utp_test
import ( import (
"context"
"testing" "testing"
"v2ray.com/core/common/buf" "v2ray.com/core/common/buf"
@ -12,7 +13,10 @@ func TestUTPWrite(t *testing.T) {
assert := With(t) assert := With(t)
content := []byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'} 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 := buf.NewLocal(2048)
payload.AppendSupplier(utp.Write) payload.AppendSupplier(utp.Write)

View File

@ -25,6 +25,7 @@ func (vc *VideoChat) Write(b []byte) (int, error) {
return 13, nil return 13, nil
} }
// NewVideoChat returns a new VideoChat instance based on given config.
func NewVideoChat(ctx context.Context, config interface{}) (interface{}, error) { func NewVideoChat(ctx context.Context, config interface{}) (interface{}, error) {
return &VideoChat{ return &VideoChat{
sn: int(dice.RollUint16()), sn: int(dice.RollUint16()),

View File

@ -1,6 +1,7 @@
package wechat_test package wechat_test
import ( import (
"context"
"testing" "testing"
"v2ray.com/core/common/buf" "v2ray.com/core/common/buf"
@ -11,7 +12,10 @@ import (
func TestUTPWrite(t *testing.T) { func TestUTPWrite(t *testing.T) {
assert := With(t) assert := With(t)
video := VideoChat{} videoRaw, err := NewVideoChat(context.Background(), &VideoConfig{})
assert(err, IsNil)
video := videoRaw.(*VideoChat)
payload := buf.NewLocal(2048) payload := buf.NewLocal(2048)
payload.AppendSupplier(video.Write) payload.AppendSupplier(video.Write)