diff options
author | Jhon Honce <jhonce@redhat.com> | 2021-09-13 14:29:22 -0700 |
---|---|---|
committer | Matthew Heon <mheon@redhat.com> | 2021-09-16 09:42:14 -0400 |
commit | 74bc365eb6f036a87313ffe5acd3561d3c44638f (patch) | |
tree | a758b7fc4fe7e35c1cfd344c4d432e75160b50fe /vendor/github.com/onsi/gomega/gstruct/pointer.go | |
parent | e37883f13e6f9e659a044eaa5dba46bab166e3a6 (diff) | |
download | podman-74bc365eb6f036a87313ffe5acd3561d3c44638f.tar.gz podman-74bc365eb6f036a87313ffe5acd3561d3c44638f.tar.bz2 podman-74bc365eb6f036a87313ffe5acd3561d3c44638f.zip |
Enhance bindings for IDE hints
* Follow https://pkg.go.dev/cmd/go#hdr-Generate_Go_files_by_processing_source
for leading comment
* Add godoc strings for all exposed methods for IDE support
* Copy field godoc strings into generated code as function godoc string
* Remove unused/unnecessary fields from generator.go structures
* Cleanup code regarding template usage
Signed-off-by: Jhon Honce <jhonce@redhat.com>
Diffstat (limited to 'vendor/github.com/onsi/gomega/gstruct/pointer.go')
-rw-r--r-- | vendor/github.com/onsi/gomega/gstruct/pointer.go | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/vendor/github.com/onsi/gomega/gstruct/pointer.go b/vendor/github.com/onsi/gomega/gstruct/pointer.go new file mode 100644 index 000000000..cc828a325 --- /dev/null +++ b/vendor/github.com/onsi/gomega/gstruct/pointer.go @@ -0,0 +1,58 @@ +// 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 interface{}) (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(_ interface{}) (message string) { + return m.failure +} + +func (m *PointerMatcher) NegatedFailureMessage(actual interface{}) (message string) { + return m.Matcher.NegatedFailureMessage(actual) +} |