diff --git a/testing/unit/errorsubject.go b/testing/unit/errorsubject.go index e4612a225..271af1bef 100644 --- a/testing/unit/errorsubject.go +++ b/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)) + } +}