diff --git a/app/dns/hosts_test.go b/app/dns/hosts_test.go index fd13a5a9..87708c47 100644 --- a/app/dns/hosts_test.go +++ b/app/dns/hosts_test.go @@ -3,13 +3,13 @@ package dns_test import ( "testing" + "github.com/google/go-cmp/cmp" + . "v2ray.com/core/app/dns" - . "v2ray.com/ext/assert" + "v2ray.com/core/common" ) func TestStaticHosts(t *testing.T) { - assert := With(t) - pb := []*Config_HostMapping{ { Type: DomainMatchingType_Full, @@ -28,17 +28,25 @@ func TestStaticHosts(t *testing.T) { } hosts, err := NewStaticHosts(pb, nil) - assert(err, IsNil) + common.Must(err) { ips := hosts.LookupIP("v2ray.com") - assert(len(ips), Equals, 1) - assert([]byte(ips[0]), Equals, []byte{1, 1, 1, 1}) + if len(ips) != 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") - assert(len(ips), Equals, 1) - assert([]byte(ips[0]), Equals, []byte{2, 2, 2, 2}) + if len(ips) != 1 { + 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) + } } } diff --git a/app/dns/nameserver_test.go b/app/dns/nameserver_test.go index 1e416782..46ae837e 100644 --- a/app/dns/nameserver_test.go +++ b/app/dns/nameserver_test.go @@ -6,16 +6,16 @@ import ( "time" . "v2ray.com/core/app/dns" - . "v2ray.com/ext/assert" + "v2ray.com/core/common" ) func TestLocalNameServer(t *testing.T) { - assert := With(t) - s := NewLocalNameServer() ctx, cancel := context.WithTimeout(context.Background(), time.Second*2) ips, err := s.QueryIP(ctx, "google.com") cancel() - assert(err, IsNil) - assert(len(ips), GreaterThan, 0) + common.Must(err) + if len(ips) == 0 { + t.Error("expect some ips, but got 0") + } } diff --git a/app/log/command/command_test.go b/app/log/command/command_test.go index 03debdec..be96d757 100644 --- a/app/log/command/command_test.go +++ b/app/log/command/command_test.go @@ -11,13 +11,11 @@ import ( "v2ray.com/core/app/proxyman" _ "v2ray.com/core/app/proxyman/inbound" _ "v2ray.com/core/app/proxyman/outbound" + "v2ray.com/core/common" "v2ray.com/core/common/serial" - . "v2ray.com/ext/assert" ) func TestLoggerRestart(t *testing.T) { - assert := With(t) - v, err := core.New(&core.Config{ App: []*serial.TypedMessage{ serial.ToTypedMessage(&log.Config{}), @@ -26,13 +24,11 @@ func TestLoggerRestart(t *testing.T) { serial.ToTypedMessage(&proxyman.OutboundConfig{}), }, }) - - assert(err, IsNil) - assert(v.Start(), IsNil) + common.Must(err) + common.Must(v.Start()) server := &LoggerServer{ V: v, } - _, err = server.RestartLogger(context.Background(), &RestartLoggerRequest{}) - assert(err, IsNil) + common.Must2(server.RestartLogger(context.Background(), &RestartLoggerRequest{})) } diff --git a/common/compare/string.go b/common/compare/string.go deleted file mode 100644 index 4d48861d..00000000 --- a/common/compare/string.go +++ /dev/null @@ -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 -} diff --git a/common/errors/errors_test.go b/common/errors/errors_test.go index bda3ded3..2fd23beb 100644 --- a/common/errors/errors_test.go +++ b/common/errors/errors_test.go @@ -4,7 +4,8 @@ import ( "io" "testing" - "v2ray.com/core/common/compare" + "github.com/google/go-cmp/cmp" + . "v2ray.com/core/common/errors" "v2ray.com/core/common/log" . "v2ray.com/ext/assert" @@ -46,8 +47,8 @@ func TestErrorMessage(t *testing.T) { } for _, d := range data { - if err := compare.StringEqualWithDetail(d.msg, d.err.Error()); err != nil { - t.Fatal(err) + if diff := cmp.Diff(d.msg, d.err.Error()); diff != "" { + t.Error(diff) } } } diff --git a/common/log/log_test.go b/common/log/log_test.go index a568b7b7..63755e29 100644 --- a/common/log/log_test.go +++ b/common/log/log_test.go @@ -3,7 +3,8 @@ package log_test import ( "testing" - "v2ray.com/core/common/compare" + "github.com/google/go-cmp/cmp" + "v2ray.com/core/common/log" "v2ray.com/core/common/net" ) @@ -26,7 +27,7 @@ func TestLogRecord(t *testing.T) { Content: net.ParseAddress(ip), }) - if err := compare.StringEqualWithDetail("[Error] "+ip, logger.value); err != nil { - t.Fatal(err) + if diff := cmp.Diff("[Error] "+ip, logger.value); diff != "" { + t.Error(diff) } } diff --git a/common/protocol/address_test.go b/common/protocol/address_test.go index 9f9dd97e..8e9c19df 100644 --- a/common/protocol/address_test.go +++ b/common/protocol/address_test.go @@ -4,9 +4,10 @@ import ( "bytes" "testing" + "github.com/google/go-cmp/cmp" + "v2ray.com/core/common" "v2ray.com/core/common/buf" - "v2ray.com/core/common/compare" "v2ray.com/core/common/net" . "v2ray.com/core/common/protocol" ) @@ -134,7 +135,7 @@ func TestAddressWriting(t *testing.T) { } } else { 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) } } diff --git a/common/protocol/http/sniff_test.go b/common/protocol/http/sniff_test.go index 2499b05a..82f3b1ae 100644 --- a/common/protocol/http/sniff_test.go +++ b/common/protocol/http/sniff_test.go @@ -3,7 +3,6 @@ package http_test import ( "testing" - "v2ray.com/core/common/compare" . "v2ray.com/core/common/protocol/http" ) @@ -98,8 +97,8 @@ first_name=John&last_name=Doe&action=Submit`, if err != nil { t.Errorf("Expect no error but actually %s in test %v", err.Error(), test) } - if err := compare.StringEqualWithDetail(header.Domain(), test.domain); err != nil { - t.Error(err) + if header.Domain() != test.domain { + t.Error("expected domain ", test.domain, " but got ", header.Domain()) } } } diff --git a/common/protocol/tls/sniff_test.go b/common/protocol/tls/sniff_test.go index d3fe6262..b84166cb 100644 --- a/common/protocol/tls/sniff_test.go +++ b/common/protocol/tls/sniff_test.go @@ -3,7 +3,6 @@ package tls_test import ( "testing" - "v2ray.com/core/common/compare" . "v2ray.com/core/common/protocol/tls" ) @@ -94,8 +93,8 @@ func TestTLSHeaders(t *testing.T) { if err != nil { t.Errorf("Expect no error but actually %s in test %v", err.Error(), test) } - if err := compare.StringEqualWithDetail(header.Domain(), test.domain); err != nil { - t.Error(err) + if header.Domain() != test.domain { + t.Error("expect domain ", test.domain, " but got ", header.Domain()) } } } diff --git a/common/serial/serial_test.go b/common/serial/serial_test.go index f0c3d3a9..1988c59e 100644 --- a/common/serial/serial_test.go +++ b/common/serial/serial_test.go @@ -3,9 +3,10 @@ package serial_test import ( "testing" + "github.com/google/go-cmp/cmp" + "v2ray.com/core/common" "v2ray.com/core/common/buf" - "v2ray.com/core/common/compare" "v2ray.com/core/common/serial" ) @@ -18,7 +19,7 @@ func TestUint32Serial(t *testing.T) { if n != 4 { t.Error("expect 4 bytes writtng, but actually ", n) } - if err := compare.BytesEqualWithDetail(b.Bytes(), []byte{0, 0, 0, 10}); err != nil { - t.Error(err) + if diff := cmp.Diff(b.Bytes(), []byte{0, 0, 0, 10}); diff != "" { + t.Error(diff) } } diff --git a/common/uuid/uuid_test.go b/common/uuid/uuid_test.go index e1ccb1b4..3fdbd87b 100644 --- a/common/uuid/uuid_test.go +++ b/common/uuid/uuid_test.go @@ -3,6 +3,8 @@ package uuid_test import ( "testing" + "github.com/google/go-cmp/cmp" + "v2ray.com/core/common" "v2ray.com/core/common/compare" . "v2ray.com/core/common/uuid" @@ -15,8 +17,8 @@ func TestParseBytes(t *testing.T) { uuid, err := ParseBytes(bytes) common.Must(err) - if err := compare.StringEqualWithDetail(uuid.String(), str); err != nil { - t.Fatal(err) + if diff := cmp.Diff(uuid.String(), str); diff != "" { + t.Error(diff) } _, err = ParseBytes([]byte{1, 3, 2, 4})