1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-12-29 21:45:21 -05:00

remove dependency on assert lib

This commit is contained in:
Darien Raymond
2019-01-07 23:27:59 +01:00
parent 5f53530cc1
commit edd71de1c3
6 changed files with 246 additions and 375 deletions

View File

@@ -3,32 +3,47 @@ package net_test
import (
"testing"
"github.com/google/go-cmp/cmp"
. "v2ray.com/core/common/net"
. "v2ray.com/core/common/net/testing"
. "v2ray.com/ext/assert"
)
func TestTCPDestination(t *testing.T) {
assert := With(t)
func TestDestinationProperty(t *testing.T) {
testCases := []struct {
Input Destination
Network Network
String string
NetString string
}{
{
Input: TCPDestination(IPAddress([]byte{1, 2, 3, 4}), 80),
Network: Network_TCP,
String: "tcp:1.2.3.4:80",
NetString: "1.2.3.4:80",
},
{
Input: UDPDestination(IPAddress([]byte{0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88}), 53),
Network: Network_UDP,
String: "udp:[2001:4860:4860::8888]:53",
NetString: "[2001:4860:4860::8888]:53",
},
}
dest := TCPDestination(IPAddress([]byte{1, 2, 3, 4}), 80)
assert(dest, IsTCP)
assert(dest, Not(IsUDP))
assert(dest.String(), Equals, "tcp:1.2.3.4:80")
}
func TestUDPDestination(t *testing.T) {
assert := With(t)
dest := UDPDestination(IPAddress([]byte{0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88}), 53)
assert(dest, Not(IsTCP))
assert(dest, IsUDP)
assert(dest.String(), Equals, "udp:[2001:4860:4860::8888]:53")
for _, testCase := range testCases {
dest := testCase.Input
if r := cmp.Diff(dest.Network, testCase.Network); r != "" {
t.Error("unexpected Network in ", dest.String(), ": ", r)
}
if r := cmp.Diff(dest.String(), testCase.String); r != "" {
t.Error(r)
}
if r := cmp.Diff(dest.NetAddr(), testCase.NetString); r != "" {
t.Error(r)
}
}
}
func TestDestinationParse(t *testing.T) {
assert := With(t)
cases := []struct {
Input string
Output Destination
@@ -69,10 +84,16 @@ func TestDestinationParse(t *testing.T) {
for _, testcase := range cases {
d, err := ParseDestination(testcase.Input)
if !testcase.Error {
assert(err, IsNil)
assert(d, Equals, testcase.Output)
if err != nil {
t.Error("for test case: ", testcase.Input, " expected no error, but got ", err)
}
if d != testcase.Output {
t.Error("for test case: ", testcase.Input, " expected output: ", testcase.Output.String(), " but got ", d.String())
}
} else {
assert(err, IsNotNil)
if err == nil {
t.Error("for test case: ", testcase.Input, " expected error, but got nil")
}
}
}
}