Browse Source

fix bytes assertion

Darien Raymond 8 năm trước cách đây
mục cha
commit
14bbb58b12
1 tập tin đã thay đổi với 10 bổ sung2 xóa
  1. 10 2
      testing/assert/bytes.go

+ 10 - 2
testing/assert/bytes.go

@@ -3,6 +3,8 @@ package assert
 import (
 	"bytes"
 
+	"fmt"
+
 	"v2ray.com/core/common/serial"
 )
 
@@ -22,8 +24,14 @@ type BytesSubject struct {
 }
 
 func (subject *BytesSubject) Equals(expectation []byte) {
-	if !bytes.Equal(subject.value, expectation) {
-		subject.Fail("is equal to", serial.BytesToHexString(expectation))
+	if len(subject.value) != len(expectation) {
+		subject.FailWithMessage(fmt.Sprint("Bytes arrays have differen size: expected", len(expectation), ", actual", len(subject.value)))
+	}
+	for idx, b := range expectation {
+		if subject.value[idx] != b {
+			subject.FailWithMessage(fmt.Sprint("Bytes are different:", b, "vs", subject.value[idx]))
+			return
+		}
 	}
 }