in internal/webtest/webtest.go [385:447]
func (c *case_) check(resp *http.Response, body string) error {
var msg bytes.Buffer
for _, chk := range c.checks {
what := chk.what
if chk.whatArg != "" {
what += " " + chk.whatArg
}
var value string
switch chk.what {
default:
value = "unknown what: " + chk.what
case "body":
value = body
case "trimbody":
value = trim(body)
case "code":
value = fmt.Sprint(resp.StatusCode)
case "header":
value = resp.Header.Get(chk.whatArg)
case "redirect":
if resp.StatusCode/10 == 30 {
value = resp.Header.Get("Location")
}
}
switch chk.op {
default:
fmt.Fprintf(&msg, "%s:%d: unknown operator %s\n", chk.file, chk.line, chk.op)
case "==":
if value != chk.want {
fmt.Fprintf(&msg, "%s:%d: %s = %q, want %q\n", chk.file, chk.line, what, value, chk.want)
}
case "!=":
if value == chk.want {
fmt.Fprintf(&msg, "%s:%d: %s == %q (but want !=)\n", chk.file, chk.line, what, value)
}
case "~":
if !chk.wantRE.MatchString(value) {
fmt.Fprintf(&msg, "%s:%d: %s does not match %#q (but should)\n\t%s\n", chk.file, chk.line, what, chk.want, indent(value))
}
case "!~":
if chk.wantRE.MatchString(value) {
fmt.Fprintf(&msg, "%s:%d: %s matches %#q (but should not)\n\t%s\n", chk.file, chk.line, what, chk.want, indent(value))
}
case "contains":
if !strings.Contains(value, chk.want) {
fmt.Fprintf(&msg, "%s:%d: %s does not contain %#q (but should)\n\t%s\n", chk.file, chk.line, what, chk.want, indent(value))
}
case "!contains":
if strings.Contains(value, chk.want) {
fmt.Fprintf(&msg, "%s:%d: %s contains %#q (but should not)\n\t%s\n", chk.file, chk.line, what, chk.want, indent(value))
}
}
}
if msg.Len() > 0 && c.hint != "" {
fmt.Fprintf(&msg, "hint: %s\n", indent(c.hint))
}
if msg.Len() > 0 {
return fmt.Errorf("%s:%d: %s %s\n%s", c.file, c.line, c.method, c.url, msg.String())
}
return nil
}