Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.36.2 to 1.36.3. - [Release notes](https://github.com/onsi/gomega/releases) - [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md) - [Commits](https://github.com/onsi/gomega/compare/v1.36.2...v1.36.3) --- updated-dependencies: - dependency-name: github.com/onsi/gomega dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com>
41 lines
1.0 KiB
Go
41 lines
1.0 KiB
Go
// untested sections: 2
|
|
|
|
package matchers
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/onsi/gomega/format"
|
|
)
|
|
|
|
type ContainSubstringMatcher struct {
|
|
Substr string
|
|
Args []any
|
|
}
|
|
|
|
func (matcher *ContainSubstringMatcher) Match(actual any) (success bool, err error) {
|
|
actualString, ok := toString(actual)
|
|
if !ok {
|
|
return false, fmt.Errorf("ContainSubstring matcher requires a string or stringer. Got:\n%s", format.Object(actual, 1))
|
|
}
|
|
|
|
return strings.Contains(actualString, matcher.stringToMatch()), nil
|
|
}
|
|
|
|
func (matcher *ContainSubstringMatcher) stringToMatch() string {
|
|
stringToMatch := matcher.Substr
|
|
if len(matcher.Args) > 0 {
|
|
stringToMatch = fmt.Sprintf(matcher.Substr, matcher.Args...)
|
|
}
|
|
return stringToMatch
|
|
}
|
|
|
|
func (matcher *ContainSubstringMatcher) FailureMessage(actual any) (message string) {
|
|
return format.Message(actual, "to contain substring", matcher.stringToMatch())
|
|
}
|
|
|
|
func (matcher *ContainSubstringMatcher) NegatedFailureMessage(actual any) (message string) {
|
|
return format.Message(actual, "not to contain substring", matcher.stringToMatch())
|
|
}
|