mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 17:46:58 -05:00
remove dependency on assert lib
This commit is contained in:
parent
25f0546228
commit
c9958681f7
@ -18,7 +18,6 @@ import (
|
|||||||
"v2ray.com/core/common/protocol"
|
"v2ray.com/core/common/protocol"
|
||||||
"v2ray.com/core/common/protocol/http"
|
"v2ray.com/core/common/protocol/http"
|
||||||
"v2ray.com/core/common/session"
|
"v2ray.com/core/common/session"
|
||||||
. "v2ray.com/ext/assert"
|
|
||||||
"v2ray.com/ext/sysio"
|
"v2ray.com/ext/sysio"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -266,23 +265,46 @@ func loadGeoSite(country string) ([]*Domain, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestChinaSites(t *testing.T) {
|
func TestChinaSites(t *testing.T) {
|
||||||
assert := With(t)
|
|
||||||
|
|
||||||
common.Must(sysio.CopyFile(platform.GetAssetLocation("geosite.dat"), filepath.Join(os.Getenv("GOPATH"), "src", "v2ray.com", "core", "release", "config", "geosite.dat")))
|
common.Must(sysio.CopyFile(platform.GetAssetLocation("geosite.dat"), filepath.Join(os.Getenv("GOPATH"), "src", "v2ray.com", "core", "release", "config", "geosite.dat")))
|
||||||
|
|
||||||
domains, err := loadGeoSite("CN")
|
domains, err := loadGeoSite("CN")
|
||||||
assert(err, IsNil)
|
common.Must(err)
|
||||||
|
|
||||||
matcher, err := NewDomainMatcher(domains)
|
matcher, err := NewDomainMatcher(domains)
|
||||||
common.Must(err)
|
common.Must(err)
|
||||||
|
|
||||||
assert(matcher.ApplyDomain("163.com"), IsTrue)
|
type TestCase struct {
|
||||||
assert(matcher.ApplyDomain("163.com"), IsTrue)
|
Domain string
|
||||||
assert(matcher.ApplyDomain("164.com"), IsFalse)
|
Output bool
|
||||||
assert(matcher.ApplyDomain("164.com"), IsFalse)
|
}
|
||||||
|
testCases := []TestCase{
|
||||||
|
{
|
||||||
|
Domain: "163.com",
|
||||||
|
Output: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Domain: "163.com",
|
||||||
|
Output: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Domain: "164.com",
|
||||||
|
Output: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Domain: "164.com",
|
||||||
|
Output: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
for i := 0; i < 1024; i++ {
|
for i := 0; i < 1024; i++ {
|
||||||
assert(matcher.ApplyDomain(strconv.Itoa(i)+".not-exists.com"), IsFalse)
|
testCases = append(testCases, TestCase{Domain: strconv.Itoa(i) + ".not-exists.com", Output: false})
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
r := matcher.ApplyDomain(testCase.Domain)
|
||||||
|
if r != testCase.Output {
|
||||||
|
t.Error("expected output ", testCase.Output, " for domain ", testCase.Domain, " but got ", r)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,24 +4,33 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "v2ray.com/core/common/bitmask"
|
. "v2ray.com/core/common/bitmask"
|
||||||
. "v2ray.com/ext/assert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBitmaskByte(t *testing.T) {
|
func TestBitmaskByte(t *testing.T) {
|
||||||
assert := With(t)
|
|
||||||
|
|
||||||
b := Byte(0)
|
b := Byte(0)
|
||||||
b.Set(Byte(1))
|
b.Set(Byte(1))
|
||||||
assert(b.Has(1), IsTrue)
|
if !b.Has(1) {
|
||||||
|
t.Fatal("expected ", b, " to contain 1, but actually not")
|
||||||
|
}
|
||||||
|
|
||||||
b.Set(Byte(2))
|
b.Set(Byte(2))
|
||||||
assert(b.Has(2), IsTrue)
|
if !b.Has(2) {
|
||||||
assert(b.Has(1), IsTrue)
|
t.Fatal("expected ", b, " to contain 2, but actually not")
|
||||||
|
}
|
||||||
|
if !b.Has(1) {
|
||||||
|
t.Fatal("expected ", b, " to contain 1, but actually not")
|
||||||
|
}
|
||||||
|
|
||||||
b.Clear(Byte(1))
|
b.Clear(Byte(1))
|
||||||
assert(b.Has(2), IsTrue)
|
if !b.Has(2) {
|
||||||
assert(b.Has(1), IsFalse)
|
t.Fatal("expected ", b, " to contain 2, but actually not")
|
||||||
|
}
|
||||||
|
if b.Has(1) {
|
||||||
|
t.Fatal("expected ", b, " to not contain 1, but actually did")
|
||||||
|
}
|
||||||
|
|
||||||
b.Toggle(Byte(2))
|
b.Toggle(Byte(2))
|
||||||
assert(b.Has(2), IsFalse)
|
if b.Has(2) {
|
||||||
|
t.Fatal("expected ", b, " to not contain 2, but actually did")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,15 +4,16 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "v2ray.com/core/common/serial"
|
. "v2ray.com/core/common/serial"
|
||||||
. "v2ray.com/ext/assert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetInstance(t *testing.T) {
|
func TestGetInstance(t *testing.T) {
|
||||||
assert := With(t)
|
|
||||||
|
|
||||||
p, err := GetInstance("")
|
p, err := GetInstance("")
|
||||||
assert(p, IsNil)
|
if p != nil {
|
||||||
assert(err, IsNotNil)
|
t.Error("expected nil instance, but got ", p)
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
t.Error("expect non-nil error, but got nil")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertingNilMessage(t *testing.T) {
|
func TestConvertingNilMessage(t *testing.T) {
|
||||||
|
@ -4,12 +4,9 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "v2ray.com/core/common/signal/pubsub"
|
. "v2ray.com/core/common/signal/pubsub"
|
||||||
. "v2ray.com/ext/assert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPubsub(t *testing.T) {
|
func TestPubsub(t *testing.T) {
|
||||||
assert := With(t)
|
|
||||||
|
|
||||||
service := NewService()
|
service := NewService()
|
||||||
|
|
||||||
sub := service.Subscribe("a")
|
sub := service.Subscribe("a")
|
||||||
@ -17,7 +14,9 @@ func TestPubsub(t *testing.T) {
|
|||||||
|
|
||||||
select {
|
select {
|
||||||
case v := <-sub.Wait():
|
case v := <-sub.Wait():
|
||||||
assert(v.(int), Equals, 1)
|
if v != 1 {
|
||||||
|
t.Error("expected subscribed value 1, but got ", v)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
|
@ -4,15 +4,11 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
. "v2ray.com/core/common/task"
|
|
||||||
. "v2ray.com/ext/assert"
|
|
||||||
|
|
||||||
"v2ray.com/core/common"
|
"v2ray.com/core/common"
|
||||||
|
. "v2ray.com/core/common/task"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPeriodicTaskStop(t *testing.T) {
|
func TestPeriodicTaskStop(t *testing.T) {
|
||||||
assert := With(t)
|
|
||||||
|
|
||||||
value := 0
|
value := 0
|
||||||
task := &Periodic{
|
task := &Periodic{
|
||||||
Interval: time.Second * 2,
|
Interval: time.Second * 2,
|
||||||
@ -24,9 +20,13 @@ func TestPeriodicTaskStop(t *testing.T) {
|
|||||||
common.Must(task.Start())
|
common.Must(task.Start())
|
||||||
time.Sleep(time.Second * 5)
|
time.Sleep(time.Second * 5)
|
||||||
common.Must(task.Close())
|
common.Must(task.Close())
|
||||||
assert(value, Equals, 3)
|
if value != 3 {
|
||||||
|
t.Fatal("expected 3, but got ", value)
|
||||||
|
}
|
||||||
time.Sleep(time.Second * 4)
|
time.Sleep(time.Second * 4)
|
||||||
assert(value, Equals, 3)
|
if value != 3 {
|
||||||
|
t.Fatal("expected 3, but got ", value)
|
||||||
|
}
|
||||||
common.Must(task.Start())
|
common.Must(task.Start())
|
||||||
time.Sleep(time.Second * 3)
|
time.Sleep(time.Second * 3)
|
||||||
if value != 5 {
|
if value != 5 {
|
||||||
|
@ -3,16 +3,16 @@ package encoding_test
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/go-cmp/cmp"
|
||||||
|
|
||||||
|
"v2ray.com/core/common"
|
||||||
"v2ray.com/core/common/buf"
|
"v2ray.com/core/common/buf"
|
||||||
"v2ray.com/core/common/protocol"
|
"v2ray.com/core/common/protocol"
|
||||||
"v2ray.com/core/common/uuid"
|
"v2ray.com/core/common/uuid"
|
||||||
. "v2ray.com/core/proxy/vmess/encoding"
|
. "v2ray.com/core/proxy/vmess/encoding"
|
||||||
. "v2ray.com/ext/assert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSwitchAccount(t *testing.T) {
|
func TestSwitchAccount(t *testing.T) {
|
||||||
assert := With(t)
|
|
||||||
|
|
||||||
sa := &protocol.CommandSwitchAccount{
|
sa := &protocol.CommandSwitchAccount{
|
||||||
Port: 1234,
|
Port: 1234,
|
||||||
ID: uuid.New(),
|
ID: uuid.New(),
|
||||||
@ -22,19 +22,16 @@ func TestSwitchAccount(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buffer := buf.New()
|
buffer := buf.New()
|
||||||
err := MarshalCommand(sa, buffer)
|
common.Must(MarshalCommand(sa, buffer))
|
||||||
assert(err, IsNil)
|
|
||||||
|
|
||||||
cmd, err := UnmarshalCommand(1, buffer.BytesFrom(2))
|
cmd, err := UnmarshalCommand(1, buffer.BytesFrom(2))
|
||||||
assert(err, IsNil)
|
common.Must(err)
|
||||||
|
|
||||||
sa2, ok := cmd.(*protocol.CommandSwitchAccount)
|
sa2, ok := cmd.(*protocol.CommandSwitchAccount)
|
||||||
assert(ok, IsTrue)
|
if !ok {
|
||||||
assert(sa.Host, IsNil)
|
t.Fatal("failed to convert command to CommandSwitchAccount")
|
||||||
assert(sa2.Host, IsNil)
|
}
|
||||||
assert(sa.Port, Equals, sa2.Port)
|
if r := cmp.Diff(sa2, sa); r != "" {
|
||||||
assert(sa.ID.String(), Equals, sa2.ID.String())
|
t.Error(r)
|
||||||
assert(sa.AlterIds, Equals, sa2.AlterIds)
|
}
|
||||||
assert(byte(sa.Level), Equals, byte(sa2.Level))
|
|
||||||
assert(sa.ValidMin, Equals, sa2.ValidMin)
|
|
||||||
}
|
}
|
||||||
|
@ -4,21 +4,21 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"v2ray.com/core/common"
|
||||||
"v2ray.com/core/common/buf"
|
"v2ray.com/core/common/buf"
|
||||||
. "v2ray.com/core/transport/internet/headers/wechat"
|
. "v2ray.com/core/transport/internet/headers/wechat"
|
||||||
. "v2ray.com/ext/assert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUTPWrite(t *testing.T) {
|
func TestUTPWrite(t *testing.T) {
|
||||||
assert := With(t)
|
|
||||||
|
|
||||||
videoRaw, err := NewVideoChat(context.Background(), &VideoConfig{})
|
videoRaw, err := NewVideoChat(context.Background(), &VideoConfig{})
|
||||||
assert(err, IsNil)
|
common.Must(err)
|
||||||
|
|
||||||
video := videoRaw.(*VideoChat)
|
video := videoRaw.(*VideoChat)
|
||||||
|
|
||||||
payload := buf.New()
|
payload := buf.New()
|
||||||
video.Serialize(payload.Extend(video.Size()))
|
video.Serialize(payload.Extend(video.Size()))
|
||||||
|
|
||||||
assert(payload.Len(), Equals, video.Size())
|
if payload.Len() != video.Size() {
|
||||||
|
t.Error("expected payload size ", video.Size(), " but got ", payload.Len())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user