github.com/onsi/gomega@v1.32.0/matchers/have_existing_field_matcher.go (about) 1 package matchers 2 3 import ( 4 "errors" 5 "fmt" 6 7 "github.com/onsi/gomega/format" 8 ) 9 10 type HaveExistingFieldMatcher struct { 11 Field string 12 } 13 14 func (matcher *HaveExistingFieldMatcher) Match(actual interface{}) (success bool, err error) { 15 // we don't care about the field's actual value, just about any error in 16 // trying to find the field (or method). 17 _, err = extractField(actual, matcher.Field, "HaveExistingField") 18 if err == nil { 19 return true, nil 20 } 21 var mferr missingFieldError 22 if errors.As(err, &mferr) { 23 // missing field errors aren't errors in this context, but instead 24 // unsuccessful matches. 25 return false, nil 26 } 27 return false, err 28 } 29 30 func (matcher *HaveExistingFieldMatcher) FailureMessage(actual interface{}) (message string) { 31 return fmt.Sprintf("Expected\n%s\nto have field '%s'", format.Object(actual, 1), matcher.Field) 32 } 33 34 func (matcher *HaveExistingFieldMatcher) NegatedFailureMessage(actual interface{}) (message string) { 35 return fmt.Sprintf("Expected\n%s\nnot to have field '%s'", format.Object(actual, 1), matcher.Field) 36 }