Explorar o código

Error code check

V2Ray %!s(int64=10) %!d(string=hai) anos
pai
achega
1995594b98
Modificáronse 1 ficheiros con 12 adicións e 0 borrados
  1. 12 0
      testing/unit/errorsubject.go

+ 12 - 0
testing/unit/errorsubject.go

@@ -1,5 +1,10 @@
 package unit
 
+import (
+	"fmt"
+	"strings"
+)
+
 type ErrorSubject struct {
 	*Subject
 	value error
@@ -36,3 +41,10 @@ func (subject *ErrorSubject) IsNil() {
 		subject.FailWithMessage("Not true that " + subject.DisplayString() + " is nil.")
 	}
 }
+
+func (subject *ErrorSubject) HasCode(code int) {
+	errorPrefix := fmt.Sprintf("[Error 0x%04X]", code)
+	if !strings.Contains(subject.value.Error(), errorPrefix) {
+		subject.FailWithMessage(fmt.Sprintf("Not ture that %s has error code 0x%04X.", subject.DisplayString(), code))
+	}
+}