Skip to content

Commit

Permalink
move net/testing/assert into assert
Browse files Browse the repository at this point in the history
  • Loading branch information
DarienRaymond committed May 24, 2016
1 parent bbdc692 commit 3582b9d
Show file tree
Hide file tree
Showing 18 changed files with 43 additions and 61 deletions.
7 changes: 3 additions & 4 deletions app/dns/config_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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))
}
3 changes: 1 addition & 2 deletions app/dns/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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}))
}
21 changes: 10 additions & 11 deletions common/net/address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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")
}
Expand All @@ -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]")
}
Expand All @@ -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")
}
Expand All @@ -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")
}

Expand Down
9 changes: 4 additions & 5 deletions common/net/destination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -13,17 +12,17 @@ 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")
}

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")
}

Expand Down
3 changes: 1 addition & 2 deletions common/protocol/raw/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
Expand Down
5 changes: 2 additions & 3 deletions common/protocol/raw/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
7 changes: 3 additions & 4 deletions proxy/dokodemo/dokodemo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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},
Expand All @@ -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))
}
5 changes: 2 additions & 3 deletions proxy/freedom/freedom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
3 changes: 1 addition & 2 deletions proxy/http/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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() + "/")
Expand Down
13 changes: 6 additions & 7 deletions proxy/shadowsocks/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()
}

Expand Down Expand Up @@ -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()
}

Expand All @@ -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})
}
Expand All @@ -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})
Expand Down
3 changes: 1 addition & 2 deletions proxy/socks/protocol/socks4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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})
}

Expand Down
5 changes: 2 additions & 3 deletions proxy/socks/protocol/socks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
3 changes: 1 addition & 2 deletions proxy/socks/protocol/udp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"))
}
5 changes: 2 additions & 3 deletions shell/point/config_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()

Expand All @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ 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 {
return &AddressSubject{value: value}
}

type AddressSubject struct {
assert.Subject
Subject
value v2net.Address
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ 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 {
return &DestinationSubject{value: value}
}

type DestinationSubject struct {
assert.Subject
Subject
value v2net.Destination
}

Expand Down
Loading

0 comments on commit 3582b9d

Please sign in to comment.