mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 15:36:41 -05:00
update tests
This commit is contained in:
parent
ac4f868078
commit
24288a74a2
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
@ -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{}))
|
||||
}
|
||||
|
@ -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"
|
||||
"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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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})
|
||||
|
Loading…
Reference in New Issue
Block a user