-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresponse-validator.go
More file actions
33 lines (26 loc) · 1008 Bytes
/
response-validator.go
File metadata and controls
33 lines (26 loc) · 1008 Bytes
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
27
28
29
30
31
32
33
package arp
type ResponseValidator interface {
Validate(test *TestCase, result *TestResult) (bool, []*FieldMatcherResult, error)
}
type ResponseValidatorHandler map[string]ResponseValidator
func (rvh *ResponseValidatorHandler) Register(responseType string, handler ResponseValidator) {
(*rvh)[responseType] = handler
}
func (rvh *ResponseValidatorHandler) LoadDefaults() {
(*rvh) = make(map[string]ResponseValidator)
rvh.Register("rest", &JSONParser{})
}
func (rvh *ResponseValidatorHandler) Handle(test *TestCase, result *TestResult) (bool, []*FieldMatcherResult, error) {
// if a custom validator is given, use it
if validator, exists := (*rvh)[test.Config.Response.Type]; exists {
return validator.Validate(test, result)
}
// otherwise fall back to the built-in ones
if test.Config.Websocket {
return test.ResponseMatcher.Match(result.Response)
} else if !test.IsRPC {
return (*rvh)["rest"].Validate(test, result)
} else {
return test.ResponseMatcher.Match(result.Response)
}
}