Skip to content

Instantly share code, notes, and snippets.

@bancek
Created November 20, 2018 21:25
Show Gist options
  • Save bancek/206befaa3cfb2eb040ef9852bc6f7284 to your computer and use it in GitHub Desktop.
Save bancek/206befaa3cfb2eb040ef9852bc6f7284 to your computer and use it in GitHub Desktop.
package gomegahelpers
import (
"github.com/onsi/gomega/types"
)
func Transform(transform func(oldValue interface{}) interface{}, matcher types.GomegaMatcher) types.GomegaMatcher {
return &TransformMatcher{
Transform: transform,
Matcher: matcher,
}
}
type TransformMatcher struct {
Transform func(oldValue interface{}) interface{}
Matcher types.GomegaMatcher
}
func (m *TransformMatcher) Match(actual interface{}) (success bool, err error) {
return m.Matcher.Match(m.Transform(actual))
}
func (m *TransformMatcher) FailureMessage(actual interface{}) (message string) {
return m.Matcher.FailureMessage(m.Transform(actual))
}
func (m *TransformMatcher) NegatedFailureMessage(actual interface{}) (message string) {
return m.Matcher.NegatedFailureMessage(m.Transform(actual))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment