/
githubmirror
/
origin
Обзор
Документация
Войти
/
githubmirror
/
origin
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
vendor/github.com/onsi/gomega/gstruct/pointer.go
59 строк
1 KB
Justin Pierce
Add compat_otp package with openshift-tests-private (OTP) util implementations
11 авг 2025, 18:00
11 авг 2025, 18:00
80ac5c1
Код
Авторство
О чём код?
// untested sections: 3 package gstruct import ( "fmt" "reflect" "github.com/onsi/gomega/format" "github.com/onsi/gomega/types" ) // PointTo applies the given matcher to the value pointed to by actual. It fails if the pointer is // nil. // // actual := 5 // Expect(&actual).To(PointTo(Equal(5))) func PointTo(matcher types.GomegaMatcher) types.GomegaMatcher { return &PointerMatcher{ Matcher: matcher, } } type PointerMatcher struct { Matcher types.GomegaMatcher // Failure message. failure string } func (m *PointerMatcher) Match(actual any) (bool, error) { val := reflect.ValueOf(actual) // return error if actual type is not a pointer if val.Kind() != reflect.Ptr { return false, fmt.Errorf("PointerMatcher expects a pointer but we have '%s'", val.Kind()) } if !val.IsValid() || val.IsNil() { m.failure = format.Message(actual, "not to be <nil>") return false, nil } // Forward the value. elem := val.Elem().Interface() match, err := m.Matcher.Match(elem) if !match { m.failure = m.Matcher.FailureMessage(elem) } return match, err } func (m *PointerMatcher) FailureMessage(_ any) (message string) { return m.failure } func (m *PointerMatcher) NegatedFailureMessage(actual any) (message string) { return m.Matcher.NegatedFailureMessage(actual) }