/
body.go
26 lines (22 loc) · 1.11 KB
/
body.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package httpmock
import (
"github.com/bluesoftdev/go-http-matchers/extractor"
"github.com/bluesoftdev/go-http-matchers/predicate"
"regexp"
"strings"
)
// BodyXPathEquals checks to see if the result of the xpath expression, matches the string supplied in the 'value'
// parameter.
func BodyXPathEquals(xpath, value string) predicate.Predicate {
return predicate.ExtractedValueAccepted(extractor.ExtractXPathString(xpath), predicate.StringEquals(value))
}
// BodyXPathEqualsIgnoreCase similar to BodyXPathEquals but ignores case when comparing the strings.
func BodyXPathEqualsIgnoreCase(xpath, value string) predicate.Predicate {
return predicate.ExtractedValueAccepted(extractor.UpperCaseExtractor(extractor.ExtractXPathString(xpath)),
predicate.StringEquals(strings.ToUpper(value)))
}
// BodyXPathMatches checks to see if the result of the xpath expression, matches the regular expression given in the
// 'pattern' parameter.
func BodyXPathMatches(xpath string, pattern *regexp.Regexp) predicate.Predicate {
return predicate.ExtractedValueAccepted(extractor.ExtractXPathString(xpath), predicate.StringMatches(pattern))
}