diff --git a/app/router/condition_test.go b/app/router/condition_test.go index d5f29de38..c12ecc9cb 100644 --- a/app/router/condition_test.go +++ b/app/router/condition_test.go @@ -18,7 +18,6 @@ import ( "v2ray.com/core/common/protocol" "v2ray.com/core/common/protocol/http" "v2ray.com/core/common/session" - . "v2ray.com/ext/assert" "v2ray.com/ext/sysio" ) @@ -266,23 +265,46 @@ func loadGeoSite(country string) ([]*Domain, error) { } 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"))) domains, err := loadGeoSite("CN") - assert(err, IsNil) + common.Must(err) matcher, err := NewDomainMatcher(domains) common.Must(err) - assert(matcher.ApplyDomain("163.com"), IsTrue) - assert(matcher.ApplyDomain("163.com"), IsTrue) - assert(matcher.ApplyDomain("164.com"), IsFalse) - assert(matcher.ApplyDomain("164.com"), IsFalse) + type TestCase struct { + Domain string + Output bool + } + 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++ { - 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) + } } } diff --git a/common/bitmask/byte_test.go b/common/bitmask/byte_test.go index 2ca2a7e32..7eb532b8b 100644 --- a/common/bitmask/byte_test.go +++ b/common/bitmask/byte_test.go @@ -4,24 +4,33 @@ import ( "testing" . "v2ray.com/core/common/bitmask" - . "v2ray.com/ext/assert" ) func TestBitmaskByte(t *testing.T) { - assert := With(t) - b := Byte(0) 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)) - assert(b.Has(2), IsTrue) - assert(b.Has(1), IsTrue) + if !b.Has(2) { + 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)) - assert(b.Has(2), IsTrue) - assert(b.Has(1), IsFalse) + if !b.Has(2) { + 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)) - assert(b.Has(2), IsFalse) + if b.Has(2) { + t.Fatal("expected ", b, " to not contain 2, but actually did") + } } diff --git a/common/serial/typed_message_test.go b/common/serial/typed_message_test.go index 084beafc4..e5f3abd1a 100644 --- a/common/serial/typed_message_test.go +++ b/common/serial/typed_message_test.go @@ -4,15 +4,16 @@ import ( "testing" . "v2ray.com/core/common/serial" - . "v2ray.com/ext/assert" ) func TestGetInstance(t *testing.T) { - assert := With(t) - p, err := GetInstance("") - assert(p, IsNil) - assert(err, IsNotNil) + if p != nil { + 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) { diff --git a/common/signal/pubsub/pubsub_test.go b/common/signal/pubsub/pubsub_test.go index 99bf4e681..40fda7ef2 100644 --- a/common/signal/pubsub/pubsub_test.go +++ b/common/signal/pubsub/pubsub_test.go @@ -4,12 +4,9 @@ import ( "testing" . "v2ray.com/core/common/signal/pubsub" - . "v2ray.com/ext/assert" ) func TestPubsub(t *testing.T) { - assert := With(t) - service := NewService() sub := service.Subscribe("a") @@ -17,7 +14,9 @@ func TestPubsub(t *testing.T) { select { case v := <-sub.Wait(): - assert(v.(int), Equals, 1) + if v != 1 { + t.Error("expected subscribed value 1, but got ", v) + } default: t.Fail() } diff --git a/common/task/periodic_test.go b/common/task/periodic_test.go index a0bc5c6c7..3a4708043 100644 --- a/common/task/periodic_test.go +++ b/common/task/periodic_test.go @@ -4,15 +4,11 @@ import ( "testing" "time" - . "v2ray.com/core/common/task" - . "v2ray.com/ext/assert" - "v2ray.com/core/common" + . "v2ray.com/core/common/task" ) func TestPeriodicTaskStop(t *testing.T) { - assert := With(t) - value := 0 task := &Periodic{ Interval: time.Second * 2, @@ -24,9 +20,13 @@ func TestPeriodicTaskStop(t *testing.T) { common.Must(task.Start()) time.Sleep(time.Second * 5) common.Must(task.Close()) - assert(value, Equals, 3) + if value != 3 { + t.Fatal("expected 3, but got ", value) + } time.Sleep(time.Second * 4) - assert(value, Equals, 3) + if value != 3 { + t.Fatal("expected 3, but got ", value) + } common.Must(task.Start()) time.Sleep(time.Second * 3) if value != 5 { diff --git a/proxy/vmess/encoding/commands_test.go b/proxy/vmess/encoding/commands_test.go index f0d93bde5..a28335218 100644 --- a/proxy/vmess/encoding/commands_test.go +++ b/proxy/vmess/encoding/commands_test.go @@ -3,16 +3,16 @@ package encoding_test import ( "testing" + "github.com/google/go-cmp/cmp" + + "v2ray.com/core/common" "v2ray.com/core/common/buf" "v2ray.com/core/common/protocol" "v2ray.com/core/common/uuid" . "v2ray.com/core/proxy/vmess/encoding" - . "v2ray.com/ext/assert" ) func TestSwitchAccount(t *testing.T) { - assert := With(t) - sa := &protocol.CommandSwitchAccount{ Port: 1234, ID: uuid.New(), @@ -22,19 +22,16 @@ func TestSwitchAccount(t *testing.T) { } buffer := buf.New() - err := MarshalCommand(sa, buffer) - assert(err, IsNil) + common.Must(MarshalCommand(sa, buffer)) cmd, err := UnmarshalCommand(1, buffer.BytesFrom(2)) - assert(err, IsNil) + common.Must(err) sa2, ok := cmd.(*protocol.CommandSwitchAccount) - assert(ok, IsTrue) - assert(sa.Host, IsNil) - assert(sa2.Host, IsNil) - assert(sa.Port, Equals, sa2.Port) - assert(sa.ID.String(), Equals, sa2.ID.String()) - assert(sa.AlterIds, Equals, sa2.AlterIds) - assert(byte(sa.Level), Equals, byte(sa2.Level)) - assert(sa.ValidMin, Equals, sa2.ValidMin) + if !ok { + t.Fatal("failed to convert command to CommandSwitchAccount") + } + if r := cmp.Diff(sa2, sa); r != "" { + t.Error(r) + } } diff --git a/transport/internet/headers/wechat/wechat_test.go b/transport/internet/headers/wechat/wechat_test.go index a44e460d2..083929ef8 100644 --- a/transport/internet/headers/wechat/wechat_test.go +++ b/transport/internet/headers/wechat/wechat_test.go @@ -4,21 +4,21 @@ import ( "context" "testing" + "v2ray.com/core/common" "v2ray.com/core/common/buf" . "v2ray.com/core/transport/internet/headers/wechat" - . "v2ray.com/ext/assert" ) func TestUTPWrite(t *testing.T) { - assert := With(t) - videoRaw, err := NewVideoChat(context.Background(), &VideoConfig{}) - assert(err, IsNil) + common.Must(err) video := videoRaw.(*VideoChat) payload := buf.New() 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()) + } }