forked from BraspagDevelopers/mock-server-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
matchers.go
39 lines (34 loc) · 970 Bytes
/
matchers.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
27
28
29
30
31
32
33
34
35
36
37
38
39
package mockserver
type RequestMatcher struct {
Method string `json:"method,omitempty"`
Path string `json:"path,omitempty"`
Body BodyMatcher `json:"body,omitempty"`
Headers map[string][]string `json:"headers,omitempty"`
}
func (m RequestMatcher) WithHeader(key, value string) RequestMatcher {
if m.Headers == nil {
m.Headers = make(map[string][]string)
}
m.Headers[key] = []string{value}
return m
}
type BodyMatcher struct {
Type string `json:"type,omitempty"`
JSON map[string]interface{} `json:"json,omitempty"`
MatchType string `json:"matchType,omitempty"`
}
const (
MatchBodyJSON = "JSON"
)
const (
StrictMatch = "STRICT"
TolerantMatch = "ONLY_MATCHING_FIELDS"
)
func (m RequestMatcher) WithJSONFields(json map[string]interface{}) RequestMatcher {
m.Body = BodyMatcher{
Type: MatchBodyJSON,
JSON: json,
MatchType: TolerantMatch,
}
return m
}