mirror of https://github.com/v2ray/v2ray-core
update tests
parent
ac4f868078
commit
24288a74a2
|
@ -3,13 +3,13 @@ package dns_test
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/go-cmp/cmp"
|
||||||
|
|
||||||
. "v2ray.com/core/app/dns"
|
. "v2ray.com/core/app/dns"
|
||||||
. "v2ray.com/ext/assert"
|
"v2ray.com/core/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestStaticHosts(t *testing.T) {
|
func TestStaticHosts(t *testing.T) {
|
||||||
assert := With(t)
|
|
||||||
|
|
||||||
pb := []*Config_HostMapping{
|
pb := []*Config_HostMapping{
|
||||||
{
|
{
|
||||||
Type: DomainMatchingType_Full,
|
Type: DomainMatchingType_Full,
|
||||||
|
@ -28,17 +28,25 @@ func TestStaticHosts(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
hosts, err := NewStaticHosts(pb, nil)
|
hosts, err := NewStaticHosts(pb, nil)
|
||||||
assert(err, IsNil)
|
common.Must(err)
|
||||||
|
|
||||||
{
|
{
|
||||||
ips := hosts.LookupIP("v2ray.com")
|
ips := hosts.LookupIP("v2ray.com")
|
||||||
assert(len(ips), Equals, 1)
|
if len(ips) != 1 {
|
||||||
assert([]byte(ips[0]), Equals, []byte{1, 1, 1, 1})
|
t.Error("expect 1 IP, but got ", len(ips))
|
||||||
|
}
|
||||||
|
if diff := cmp.Diff([]byte(ips[0]), []byte{1, 1, 1, 1}); diff != "" {
|
||||||
|
t.Error(diff)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
ips := hosts.LookupIP("www.v2ray.cn")
|
ips := hosts.LookupIP("www.v2ray.cn")
|
||||||
assert(len(ips), Equals, 1)
|
if len(ips) != 1 {
|
||||||
assert([]byte(ips[0]), Equals, []byte{2, 2, 2, 2})
|
t.Error("expect 1 IP, but got ", len(ips))
|
||||||
|
}
|
||||||
|
if diff := cmp.Diff([]byte(ips[0]), []byte{2, 2, 2, 2}); diff != "" {
|
||||||
|
t.Error(diff)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,16 +6,16 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
. "v2ray.com/core/app/dns"
|
. "v2ray.com/core/app/dns"
|
||||||
. "v2ray.com/ext/assert"
|
"v2ray.com/core/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLocalNameServer(t *testing.T) {
|
func TestLocalNameServer(t *testing.T) {
|
||||||
assert := With(t)
|
|
||||||
|
|
||||||
s := NewLocalNameServer()
|
s := NewLocalNameServer()
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*2)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*2)
|
||||||
ips, err := s.QueryIP(ctx, "google.com")
|
ips, err := s.QueryIP(ctx, "google.com")
|
||||||
cancel()
|
cancel()
|
||||||
assert(err, IsNil)
|
common.Must(err)
|
||||||
assert(len(ips), GreaterThan, 0)
|
if len(ips) == 0 {
|
||||||
|
t.Error("expect some ips, but got 0")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,13 +11,11 @@ import (
|
||||||
"v2ray.com/core/app/proxyman"
|
"v2ray.com/core/app/proxyman"
|
||||||
_ "v2ray.com/core/app/proxyman/inbound"
|
_ "v2ray.com/core/app/proxyman/inbound"
|
||||||
_ "v2ray.com/core/app/proxyman/outbound"
|
_ "v2ray.com/core/app/proxyman/outbound"
|
||||||
|
"v2ray.com/core/common"
|
||||||
"v2ray.com/core/common/serial"
|
"v2ray.com/core/common/serial"
|
||||||
. "v2ray.com/ext/assert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLoggerRestart(t *testing.T) {
|
func TestLoggerRestart(t *testing.T) {
|
||||||
assert := With(t)
|
|
||||||
|
|
||||||
v, err := core.New(&core.Config{
|
v, err := core.New(&core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{}),
|
serial.ToTypedMessage(&log.Config{}),
|
||||||
|
@ -26,13 +24,11 @@ func TestLoggerRestart(t *testing.T) {
|
||||||
serial.ToTypedMessage(&proxyman.OutboundConfig{}),
|
serial.ToTypedMessage(&proxyman.OutboundConfig{}),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
common.Must(err)
|
||||||
assert(err, IsNil)
|
common.Must(v.Start())
|
||||||
assert(v.Start(), IsNil)
|
|
||||||
|
|
||||||
server := &LoggerServer{
|
server := &LoggerServer{
|
||||||
V: v,
|
V: v,
|
||||||
}
|
}
|
||||||
_, err = server.RestartLogger(context.Background(), &RestartLoggerRequest{})
|
common.Must2(server.RestartLogger(context.Background(), &RestartLoggerRequest{}))
|
||||||
assert(err, IsNil)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
package compare
|
|
||||||
|
|
||||||
import "v2ray.com/core/common/errors"
|
|
||||||
|
|
||||||
func StringEqualWithDetail(a string, b string) error {
|
|
||||||
if a != b {
|
|
||||||
return errors.New("Got ", b, " but want ", a)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
|
@ -4,7 +4,8 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"v2ray.com/core/common/compare"
|
"github.com/google/go-cmp/cmp"
|
||||||
|
|
||||||
. "v2ray.com/core/common/errors"
|
. "v2ray.com/core/common/errors"
|
||||||
"v2ray.com/core/common/log"
|
"v2ray.com/core/common/log"
|
||||||
. "v2ray.com/ext/assert"
|
. "v2ray.com/ext/assert"
|
||||||
|
@ -46,8 +47,8 @@ func TestErrorMessage(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, d := range data {
|
for _, d := range data {
|
||||||
if err := compare.StringEqualWithDetail(d.msg, d.err.Error()); err != nil {
|
if diff := cmp.Diff(d.msg, d.err.Error()); diff != "" {
|
||||||
t.Fatal(err)
|
t.Error(diff)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,8 @@ package log_test
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"v2ray.com/core/common/compare"
|
"github.com/google/go-cmp/cmp"
|
||||||
|
|
||||||
"v2ray.com/core/common/log"
|
"v2ray.com/core/common/log"
|
||||||
"v2ray.com/core/common/net"
|
"v2ray.com/core/common/net"
|
||||||
)
|
)
|
||||||
|
@ -26,7 +27,7 @@ func TestLogRecord(t *testing.T) {
|
||||||
Content: net.ParseAddress(ip),
|
Content: net.ParseAddress(ip),
|
||||||
})
|
})
|
||||||
|
|
||||||
if err := compare.StringEqualWithDetail("[Error] "+ip, logger.value); err != nil {
|
if diff := cmp.Diff("[Error] "+ip, logger.value); diff != "" {
|
||||||
t.Fatal(err)
|
t.Error(diff)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,10 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/go-cmp/cmp"
|
||||||
|
|
||||||
"v2ray.com/core/common"
|
"v2ray.com/core/common"
|
||||||
"v2ray.com/core/common/buf"
|
"v2ray.com/core/common/buf"
|
||||||
"v2ray.com/core/common/compare"
|
|
||||||
"v2ray.com/core/common/net"
|
"v2ray.com/core/common/net"
|
||||||
. "v2ray.com/core/common/protocol"
|
. "v2ray.com/core/common/protocol"
|
||||||
)
|
)
|
||||||
|
@ -134,7 +135,7 @@ func TestAddressWriting(t *testing.T) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
common.Must(err)
|
common.Must(err)
|
||||||
if err := compare.BytesEqualWithDetail(tc.Bytes, b.Bytes()); err != nil {
|
if diff := cmp.Diff(tc.Bytes, b.Bytes()); diff != "" {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ package http_test
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"v2ray.com/core/common/compare"
|
|
||||||
. "v2ray.com/core/common/protocol/http"
|
. "v2ray.com/core/common/protocol/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -98,8 +97,8 @@ first_name=John&last_name=Doe&action=Submit`,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Expect no error but actually %s in test %v", err.Error(), test)
|
t.Errorf("Expect no error but actually %s in test %v", err.Error(), test)
|
||||||
}
|
}
|
||||||
if err := compare.StringEqualWithDetail(header.Domain(), test.domain); err != nil {
|
if header.Domain() != test.domain {
|
||||||
t.Error(err)
|
t.Error("expected domain ", test.domain, " but got ", header.Domain())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ package tls_test
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"v2ray.com/core/common/compare"
|
|
||||||
. "v2ray.com/core/common/protocol/tls"
|
. "v2ray.com/core/common/protocol/tls"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -94,8 +93,8 @@ func TestTLSHeaders(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Expect no error but actually %s in test %v", err.Error(), test)
|
t.Errorf("Expect no error but actually %s in test %v", err.Error(), test)
|
||||||
}
|
}
|
||||||
if err := compare.StringEqualWithDetail(header.Domain(), test.domain); err != nil {
|
if header.Domain() != test.domain {
|
||||||
t.Error(err)
|
t.Error("expect domain ", test.domain, " but got ", header.Domain())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,10 @@ package serial_test
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/go-cmp/cmp"
|
||||||
|
|
||||||
"v2ray.com/core/common"
|
"v2ray.com/core/common"
|
||||||
"v2ray.com/core/common/buf"
|
"v2ray.com/core/common/buf"
|
||||||
"v2ray.com/core/common/compare"
|
|
||||||
"v2ray.com/core/common/serial"
|
"v2ray.com/core/common/serial"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,7 +19,7 @@ func TestUint32Serial(t *testing.T) {
|
||||||
if n != 4 {
|
if n != 4 {
|
||||||
t.Error("expect 4 bytes writtng, but actually ", n)
|
t.Error("expect 4 bytes writtng, but actually ", n)
|
||||||
}
|
}
|
||||||
if err := compare.BytesEqualWithDetail(b.Bytes(), []byte{0, 0, 0, 10}); err != nil {
|
if diff := cmp.Diff(b.Bytes(), []byte{0, 0, 0, 10}); diff != "" {
|
||||||
t.Error(err)
|
t.Error(diff)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ package uuid_test
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/go-cmp/cmp"
|
||||||
|
|
||||||
"v2ray.com/core/common"
|
"v2ray.com/core/common"
|
||||||
"v2ray.com/core/common/compare"
|
"v2ray.com/core/common/compare"
|
||||||
. "v2ray.com/core/common/uuid"
|
. "v2ray.com/core/common/uuid"
|
||||||
|
@ -15,8 +17,8 @@ func TestParseBytes(t *testing.T) {
|
||||||
|
|
||||||
uuid, err := ParseBytes(bytes)
|
uuid, err := ParseBytes(bytes)
|
||||||
common.Must(err)
|
common.Must(err)
|
||||||
if err := compare.StringEqualWithDetail(uuid.String(), str); err != nil {
|
if diff := cmp.Diff(uuid.String(), str); diff != "" {
|
||||||
t.Fatal(err)
|
t.Error(diff)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = ParseBytes([]byte{1, 3, 2, 4})
|
_, err = ParseBytes([]byte{1, 3, 2, 4})
|
||||||
|
|
Loading…
Reference in New Issue