mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-12-27 20:45:28 -05:00
massive refactoring against unit test lib
This commit is contained in:
41
testing/assert/errorsubject.go
Normal file
41
testing/assert/errorsubject.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package assert
|
||||
|
||||
func Error(value error) *ErrorSubject {
|
||||
return &ErrorSubject{value: value}
|
||||
}
|
||||
|
||||
type ErrorSubject struct {
|
||||
Subject
|
||||
value error
|
||||
}
|
||||
|
||||
func (subject *ErrorSubject) Named(name string) *ErrorSubject {
|
||||
subject.Subject.Named(name)
|
||||
return subject
|
||||
}
|
||||
|
||||
func (subject *ErrorSubject) Fail(verb string, other error) {
|
||||
subject.FailWithMessage("Not true that " + subject.DisplayString() + " " + verb + " <" + other.Error() + ">.")
|
||||
}
|
||||
|
||||
func (subject *ErrorSubject) DisplayString() string {
|
||||
return subject.Subject.DisplayString(subject.value.Error())
|
||||
}
|
||||
|
||||
func (subject *ErrorSubject) Equals(expectation error) {
|
||||
if subject.value != expectation {
|
||||
subject.Fail("is equal to", expectation)
|
||||
}
|
||||
}
|
||||
|
||||
func (subject *ErrorSubject) IsNil() {
|
||||
if subject.value != nil {
|
||||
subject.FailWithMessage("Not true that " + subject.DisplayString() + " is nil.")
|
||||
}
|
||||
}
|
||||
|
||||
func (subject *ErrorSubject) IsNotNil() {
|
||||
if subject.value == nil {
|
||||
subject.FailWithMessage("Not true that the error is not nil.")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user