瀏覽代碼

move net/testing/assert into assert

v2ray 9 年之前
父節點
當前提交
3582b9d869

+ 3 - 4
app/dns/config_json_test.go

@@ -8,7 +8,6 @@ import (
 
 	. "github.com/v2ray/v2ray-core/app/dns"
 	v2net "github.com/v2ray/v2ray-core/common/net"
-	netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
 	v2testing "github.com/v2ray/v2ray-core/testing"
 	"github.com/v2ray/v2ray-core/testing/assert"
 )
@@ -24,7 +23,7 @@ func TestConfigParsing(t *testing.T) {
 	err := json.Unmarshal([]byte(rawJson), config)
 	assert.Error(err).IsNil()
 	assert.Int(len(config.NameServers)).Equals(1)
-	netassert.Destination(config.NameServers[0]).IsUDP()
-	netassert.Address(config.NameServers[0].Address()).Equals(v2net.IPAddress([]byte{8, 8, 8, 8}))
-	netassert.Port(config.NameServers[0].Port()).Equals(v2net.Port(53))
+	assert.Destination(config.NameServers[0]).IsUDP()
+	assert.Address(config.NameServers[0].Address()).Equals(v2net.IPAddress([]byte{8, 8, 8, 8}))
+	assert.Port(config.NameServers[0].Port()).Equals(v2net.Port(53))
 }

+ 1 - 2
app/dns/server_test.go

@@ -10,7 +10,6 @@ import (
 	. "github.com/v2ray/v2ray-core/app/dns"
 	"github.com/v2ray/v2ray-core/app/proxyman"
 	v2net "github.com/v2ray/v2ray-core/common/net"
-	netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
 	"github.com/v2ray/v2ray-core/proxy/freedom"
 	v2testing "github.com/v2ray/v2ray-core/testing"
 	"github.com/v2ray/v2ray-core/testing/assert"
@@ -37,5 +36,5 @@ func TestDnsAdd(t *testing.T) {
 
 	ips := server.Get(domain)
 	assert.Int(len(ips)).Equals(1)
-	netassert.IP(ips[0].To4()).Equals(net.IP([]byte{127, 0, 0, 1}))
+	assert.IP(ips[0].To4()).Equals(net.IP([]byte{127, 0, 0, 1}))
 }

+ 10 - 11
common/net/address_test.go

@@ -5,7 +5,6 @@ import (
 	"testing"
 
 	v2net "github.com/v2ray/v2ray-core/common/net"
-	v2netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
 	v2testing "github.com/v2ray/v2ray-core/testing"
 	"github.com/v2ray/v2ray-core/testing/assert"
 )
@@ -16,9 +15,9 @@ func TestIPv4Address(t *testing.T) {
 	ip := []byte{byte(1), byte(2), byte(3), byte(4)}
 	addr := v2net.IPAddress(ip)
 
-	v2netassert.Address(addr).IsIPv4()
-	v2netassert.Address(addr).IsNotIPv6()
-	v2netassert.Address(addr).IsNotDomain()
+	assert.Address(addr).IsIPv4()
+	assert.Address(addr).IsNotIPv6()
+	assert.Address(addr).IsNotDomain()
 	assert.Bytes(addr.IP()).Equals(ip)
 	assert.String(addr).Equals("1.2.3.4")
 }
@@ -34,9 +33,9 @@ func TestIPv6Address(t *testing.T) {
 	}
 	addr := v2net.IPAddress(ip)
 
-	v2netassert.Address(addr).IsIPv6()
-	v2netassert.Address(addr).IsNotIPv4()
-	v2netassert.Address(addr).IsNotDomain()
+	assert.Address(addr).IsIPv6()
+	assert.Address(addr).IsNotIPv4()
+	assert.Address(addr).IsNotDomain()
 	assert.Bytes(addr.IP()).Equals(ip)
 	assert.String(addr).Equals("[102:304:102:304:102:304:102:304]")
 }
@@ -59,9 +58,9 @@ func TestDomainAddress(t *testing.T) {
 	domain := "v2ray.com"
 	addr := v2net.DomainAddress(domain)
 
-	v2netassert.Address(addr).IsDomain()
-	v2netassert.Address(addr).IsNotIPv6()
-	v2netassert.Address(addr).IsNotIPv4()
+	assert.Address(addr).IsDomain()
+	assert.Address(addr).IsNotIPv6()
+	assert.Address(addr).IsNotIPv4()
 	assert.StringLiteral(addr.Domain()).Equals(domain)
 	assert.String(addr).Equals("v2ray.com")
 }
@@ -71,7 +70,7 @@ func TestNetIPv4Address(t *testing.T) {
 
 	ip := net.IPv4(1, 2, 3, 4)
 	addr := v2net.IPAddress(ip)
-	v2netassert.Address(addr).IsIPv4()
+	assert.Address(addr).IsIPv4()
 	assert.String(addr).Equals("1.2.3.4")
 }
 

+ 4 - 5
common/net/destination_test.go

@@ -4,7 +4,6 @@ import (
 	"testing"
 
 	v2net "github.com/v2ray/v2ray-core/common/net"
-	v2netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
 	v2testing "github.com/v2ray/v2ray-core/testing"
 	"github.com/v2ray/v2ray-core/testing/assert"
 )
@@ -13,8 +12,8 @@ func TestTCPDestination(t *testing.T) {
 	v2testing.Current(t)
 
 	dest := v2net.TCPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
-	v2netassert.Destination(dest).IsTCP()
-	v2netassert.Destination(dest).IsNotUDP()
+	assert.Destination(dest).IsTCP()
+	assert.Destination(dest).IsNotUDP()
 	assert.String(dest).Equals("tcp:1.2.3.4:80")
 }
 
@@ -22,8 +21,8 @@ func TestUDPDestination(t *testing.T) {
 	v2testing.Current(t)
 
 	dest := v2net.UDPDestination(v2net.IPAddress([]byte{0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88}), 53)
-	v2netassert.Destination(dest).IsNotTCP()
-	v2netassert.Destination(dest).IsUDP()
+	assert.Destination(dest).IsNotTCP()
+	assert.Destination(dest).IsUDP()
 	assert.String(dest).Equals("udp:[2001:4860:4860::8888]:53")
 }
 

+ 1 - 2
common/protocol/raw/commands_test.go

@@ -4,7 +4,6 @@ import (
 	"testing"
 
 	"github.com/v2ray/v2ray-core/common/alloc"
-	netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
 	"github.com/v2ray/v2ray-core/common/protocol"
 	. "github.com/v2ray/v2ray-core/common/protocol/raw"
 	"github.com/v2ray/v2ray-core/common/uuid"
@@ -34,7 +33,7 @@ func TestSwitchAccount(t *testing.T) {
 	assert.Bool(ok).IsTrue()
 	assert.Pointer(sa.Host).IsNil()
 	assert.Pointer(sa2.Host).IsNil()
-	netassert.Port(sa.Port).Equals(sa2.Port)
+	assert.Port(sa.Port).Equals(sa2.Port)
 	assert.String(sa.ID).Equals(sa2.ID.String())
 	assert.Uint16(sa.AlterIds.Value()).Equals(sa2.AlterIds.Value())
 	assert.Byte(byte(sa.Level)).Equals(byte(sa2.Level))

+ 2 - 3
common/protocol/raw/encoding_test.go

@@ -5,7 +5,6 @@ import (
 
 	"github.com/v2ray/v2ray-core/common/alloc"
 	v2net "github.com/v2ray/v2ray-core/common/net"
-	netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
 	"github.com/v2ray/v2ray-core/common/protocol"
 	. "github.com/v2ray/v2ray-core/common/protocol/raw"
 	"github.com/v2ray/v2ray-core/common/uuid"
@@ -45,6 +44,6 @@ func TestRequestSerialization(t *testing.T) {
 	assert.Byte(expectedRequest.Version).Equals(actualRequest.Version)
 	assert.Byte(byte(expectedRequest.Command)).Equals(byte(actualRequest.Command))
 	assert.Byte(byte(expectedRequest.Option)).Equals(byte(actualRequest.Option))
-	netassert.Address(expectedRequest.Address).Equals(actualRequest.Address)
-	netassert.Port(expectedRequest.Port).Equals(actualRequest.Port)
+	assert.Address(expectedRequest.Address).Equals(actualRequest.Address)
+	assert.Port(expectedRequest.Port).Equals(actualRequest.Port)
 }

+ 3 - 4
proxy/dokodemo/dokodemo_test.go

@@ -10,7 +10,6 @@ import (
 	"github.com/v2ray/v2ray-core/app/proxyman"
 	v2net "github.com/v2ray/v2ray-core/common/net"
 	v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
-	netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
 	. "github.com/v2ray/v2ray-core/proxy/dokodemo"
 	"github.com/v2ray/v2ray-core/proxy/freedom"
 	v2testing "github.com/v2ray/v2ray-core/testing"
@@ -57,7 +56,7 @@ func TestDokodemoTCP(t *testing.T) {
 	port := v2nettesting.PickPort()
 	err = dokodemo.Listen(port)
 	assert.Error(err).IsNil()
-	netassert.Port(port).Equals(dokodemo.Port())
+	assert.Port(port).Equals(dokodemo.Port())
 
 	tcpClient, err := net.DialTCP("tcp", nil, &net.TCPAddr{
 		IP:   []byte{127, 0, 0, 1},
@@ -115,7 +114,7 @@ func TestDokodemoUDP(t *testing.T) {
 	port := v2nettesting.PickPort()
 	err = dokodemo.Listen(port)
 	assert.Error(err).IsNil()
-	netassert.Port(port).Equals(dokodemo.Port())
+	assert.Port(port).Equals(dokodemo.Port())
 
 	udpClient, err := net.DialUDP("udp", nil, &net.UDPAddr{
 		IP:   []byte{127, 0, 0, 1},
@@ -130,6 +129,6 @@ func TestDokodemoUDP(t *testing.T) {
 	response := make([]byte, 1024)
 	nBytes, addr, err := udpClient.ReadFromUDP(response)
 	assert.Error(err).IsNil()
-	netassert.IP(addr.IP).Equals(v2net.LocalHostIP.IP())
+	assert.IP(addr.IP).Equals(v2net.LocalHostIP.IP())
 	assert.Bytes(response[:nBytes]).Equals([]byte("Processed: " + data2Send))
 }

+ 2 - 3
proxy/freedom/freedom_test.go

@@ -14,7 +14,6 @@ import (
 	"github.com/v2ray/v2ray-core/common/alloc"
 	v2net "github.com/v2ray/v2ray-core/common/net"
 	v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
-	netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
 	. "github.com/v2ray/v2ray-core/proxy/freedom"
 	v2testing "github.com/v2ray/v2ray-core/testing"
 	"github.com/v2ray/v2ray-core/testing/assert"
@@ -88,6 +87,6 @@ func TestIPResolution(t *testing.T) {
 	space.Initialize()
 
 	ipDest := freedom.ResolveIP(v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), v2net.Port(80)))
-	netassert.Destination(ipDest).IsTCP()
-	netassert.Address(ipDest.Address()).Equals(v2net.LocalHostIP)
+	assert.Destination(ipDest).IsTCP()
+	assert.Address(ipDest.Address()).Equals(v2net.LocalHostIP)
 }

+ 1 - 2
proxy/http/server_test.go

@@ -8,7 +8,6 @@ import (
 
 	testdispatcher "github.com/v2ray/v2ray-core/app/dispatcher/testing"
 	v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
-	netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
 	. "github.com/v2ray/v2ray-core/proxy/http"
 	v2testing "github.com/v2ray/v2ray-core/testing"
 	"github.com/v2ray/v2ray-core/testing/assert"
@@ -59,7 +58,7 @@ func TestNormalGetRequest(t *testing.T) {
 	port := v2nettesting.PickPort()
 	err := httpProxy.Listen(port)
 	assert.Error(err).IsNil()
-	netassert.Port(port).Equals(httpProxy.Port())
+	assert.Port(port).Equals(httpProxy.Port())
 
 	httpClient := &http.Client{}
 	resp, err := httpClient.Get("http://127.0.0.1:" + port.String() + "/")

+ 6 - 7
proxy/shadowsocks/protocol_test.go

@@ -5,7 +5,6 @@ import (
 
 	"github.com/v2ray/v2ray-core/common/alloc"
 	v2net "github.com/v2ray/v2ray-core/common/net"
-	netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
 	"github.com/v2ray/v2ray-core/proxy"
 	. "github.com/v2ray/v2ray-core/proxy/shadowsocks"
 	v2testing "github.com/v2ray/v2ray-core/testing"
@@ -21,8 +20,8 @@ func TestNormalRequestParsing(t *testing.T) {
 
 	request, err := ReadRequest(buffer, nil, false)
 	assert.Error(err).IsNil()
-	netassert.Address(request.Address).Equals(v2net.LocalHostIP)
-	netassert.Port(request.Port).Equals(v2net.Port(80))
+	assert.Address(request.Address).Equals(v2net.LocalHostIP)
+	assert.Port(request.Port).Equals(v2net.Port(80))
 	assert.Bool(request.OTA).IsFalse()
 }
 
@@ -85,7 +84,7 @@ func TestOTARequest(t *testing.T) {
 		[]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5}))
 	request, err := ReadRequest(buffer, auth, false)
 	assert.Error(err).IsNil()
-	netassert.Address(request.Address).Equals(v2net.DomainAddress("www.v2ray.com"))
+	assert.Address(request.Address).Equals(v2net.DomainAddress("www.v2ray.com"))
 	assert.Bool(request.OTA).IsTrue()
 }
 
@@ -110,8 +109,8 @@ func TestUDPRequestParsing(t *testing.T) {
 
 	request, err := ReadRequest(buffer, nil, true)
 	assert.Error(err).IsNil()
-	netassert.Address(request.Address).Equals(v2net.LocalHostIP)
-	netassert.Port(request.Port).Equals(v2net.Port(80))
+	assert.Address(request.Address).Equals(v2net.LocalHostIP)
+	assert.Port(request.Port).Equals(v2net.Port(80))
 	assert.Bool(request.OTA).IsFalse()
 	assert.Bytes(request.UDPPayload.Value).Equals([]byte{1, 2, 3, 4, 5, 6})
 }
@@ -130,7 +129,7 @@ func TestUDPRequestWithOTA(t *testing.T) {
 		[]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5}))
 	request, err := ReadRequest(buffer, auth, true)
 	assert.Error(err).IsNil()
-	netassert.Address(request.Address).Equals(v2net.DomainAddress("www.v2ray.com"))
+	assert.Address(request.Address).Equals(v2net.DomainAddress("www.v2ray.com"))
 	assert.Bool(request.OTA).IsTrue()
 	assert.Bytes(request.UDPPayload.Value).Equals([]byte{
 		1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0})

+ 1 - 2
proxy/socks/protocol/socks4_test.go

@@ -6,7 +6,6 @@ import (
 
 	"github.com/v2ray/v2ray-core/common/alloc"
 	v2net "github.com/v2ray/v2ray-core/common/net"
-	v2netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
 	v2testing "github.com/v2ray/v2ray-core/testing"
 	"github.com/v2ray/v2ray-core/testing/assert"
 )
@@ -24,7 +23,7 @@ func TestSocks4AuthenticationRequestRead(t *testing.T) {
 	assert.Error(err).Equals(Socks4Downgrade)
 	assert.Byte(request4.Version).Named("Version").Equals(0x04)
 	assert.Byte(request4.Command).Named("Command").Equals(0x01)
-	v2netassert.Port(request4.Port).Named("Port").Equals(v2net.Port(53))
+	assert.Port(request4.Port).Named("Port").Equals(v2net.Port(53))
 	assert.Bytes(request4.IP[:]).Named("IP").Equals([]byte{0x72, 0x72, 0x72, 0x72})
 }
 

+ 2 - 3
proxy/socks/protocol/socks_test.go

@@ -7,7 +7,6 @@ import (
 
 	"github.com/v2ray/v2ray-core/common/alloc"
 	v2net "github.com/v2ray/v2ray-core/common/net"
-	v2netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
 	"github.com/v2ray/v2ray-core/proxy"
 	v2testing "github.com/v2ray/v2ray-core/testing"
 	"github.com/v2ray/v2ray-core/testing/assert"
@@ -71,7 +70,7 @@ func TestRequestRead(t *testing.T) {
 	assert.Byte(request.Command).Named("Command").Equals(0x01)
 	assert.Byte(request.AddrType).Named("Address Type").Equals(0x01)
 	assert.Bytes(request.IPv4[:]).Named("IPv4").Equals([]byte{0x72, 0x72, 0x72, 0x72})
-	v2netassert.Port(request.Port).Named("Port").Equals(v2net.Port(53))
+	assert.Port(request.Port).Named("Port").Equals(v2net.Port(53))
 }
 
 func TestResponseWrite(t *testing.T) {
@@ -170,5 +169,5 @@ func TestIPv6Request(t *testing.T) {
 	assert.Error(err).IsNil()
 	assert.Byte(request.Command).Equals(1)
 	assert.Bytes(request.IPv6[:]).Equals([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6})
-	v2netassert.Port(request.Port).Equals(8)
+	assert.Port(request.Port).Equals(8)
 }

+ 1 - 2
proxy/socks/protocol/udp_test.go

@@ -4,7 +4,6 @@ import (
 	"testing"
 
 	v2net "github.com/v2ray/v2ray-core/common/net"
-	netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
 	v2testing "github.com/v2ray/v2ray-core/testing"
 	"github.com/v2ray/v2ray-core/testing/assert"
 	"github.com/v2ray/v2ray-core/transport"
@@ -34,6 +33,6 @@ func TestDomainAddressRequest(t *testing.T) {
 
 	assert.Byte(request.Fragment).Equals(1)
 	assert.String(request.Address).Equals("v2ray.com")
-	netassert.Port(request.Port).Equals(v2net.Port(80))
+	assert.Port(request.Port).Equals(v2net.Port(80))
 	assert.Bytes(request.Data.Value).Equals([]byte("Actual payload"))
 }

+ 2 - 3
shell/point/config_json_test.go

@@ -9,7 +9,6 @@ import (
 	"testing"
 
 	_ "github.com/v2ray/v2ray-core/app/router/rules"
-	netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
 	. "github.com/v2ray/v2ray-core/shell/point"
 
 	v2testing "github.com/v2ray/v2ray-core/testing"
@@ -25,7 +24,7 @@ func TestClientSampleConfig(t *testing.T) {
 	pointConfig, err := LoadConfig(filepath.Join(baseDir, "vpoint_socks_vmess.json"))
 	assert.Error(err).IsNil()
 
-	netassert.Port(pointConfig.Port).IsValid()
+	assert.Port(pointConfig.Port).IsValid()
 	assert.Pointer(pointConfig.InboundConfig).IsNotNil()
 	assert.Pointer(pointConfig.OutboundConfig).IsNotNil()
 
@@ -45,7 +44,7 @@ func TestServerSampleConfig(t *testing.T) {
 	pointConfig, err := LoadConfig(filepath.Join(baseDir, "vpoint_vmess_freedom.json"))
 	assert.Error(err).IsNil()
 
-	netassert.Port(pointConfig.Port).IsValid()
+	assert.Port(pointConfig.Port).IsValid()
 	assert.Pointer(pointConfig.InboundConfig).IsNotNil()
 	assert.Pointer(pointConfig.OutboundConfig).IsNotNil()
 

+ 1 - 2
common/net/testing/assert/address.go → testing/assert/address.go

@@ -3,7 +3,6 @@ package assert
 import (
 	v2net "github.com/v2ray/v2ray-core/common/net"
 	"github.com/v2ray/v2ray-core/common/serial"
-	"github.com/v2ray/v2ray-core/testing/assert"
 )
 
 func Address(value v2net.Address) *AddressSubject {
@@ -11,7 +10,7 @@ func Address(value v2net.Address) *AddressSubject {
 }
 
 type AddressSubject struct {
-	assert.Subject
+	Subject
 	value v2net.Address
 }
 

+ 1 - 2
common/net/testing/assert/destination.go → testing/assert/destination.go

@@ -3,7 +3,6 @@ package assert
 import (
 	v2net "github.com/v2ray/v2ray-core/common/net"
 	"github.com/v2ray/v2ray-core/common/serial"
-	"github.com/v2ray/v2ray-core/testing/assert"
 )
 
 func Destination(value v2net.Destination) *DestinationSubject {
@@ -11,7 +10,7 @@ func Destination(value v2net.Destination) *DestinationSubject {
 }
 
 type DestinationSubject struct {
-	assert.Subject
+	Subject
 	value v2net.Destination
 }
 

+ 1 - 2
common/net/testing/assert/ip.go → testing/assert/ip.go

@@ -5,7 +5,6 @@ import (
 	"net"
 
 	"github.com/v2ray/v2ray-core/common/serial"
-	"github.com/v2ray/v2ray-core/testing/assert"
 )
 
 func IP(value net.IP) *IPSubject {
@@ -13,7 +12,7 @@ func IP(value net.IP) *IPSubject {
 }
 
 type IPSubject struct {
-	assert.Subject
+	Subject
 	value net.IP
 }
 

+ 1 - 2
common/net/testing/assert/port.go → testing/assert/port.go

@@ -3,7 +3,6 @@ package assert
 import (
 	v2net "github.com/v2ray/v2ray-core/common/net"
 	"github.com/v2ray/v2ray-core/common/serial"
-	"github.com/v2ray/v2ray-core/testing/assert"
 )
 
 func Port(value v2net.Port) *PortSubject {
@@ -11,7 +10,7 @@ func Port(value v2net.Port) *PortSubject {
 }
 
 type PortSubject struct {
-	assert.Subject
+	Subject
 	value v2net.Port
 }