-
Notifications
You must be signed in to change notification settings - Fork 0
/
match_predicate.go
36 lines (33 loc) · 1.08 KB
/
match_predicate.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
package utils
import (
"fmt"
"github.com/bhatti/api-mock-service/internal/fuzz"
"github.com/bhatti/api-mock-service/internal/types"
log "github.com/sirupsen/logrus"
)
// MatchScenarioPredicate checks if predicate match
func MatchScenarioPredicate(matched *types.APIKeyData, target *types.APIKeyData, requestCount uint64) bool {
if matched.Predicate == "" {
return true
}
// Find any params for query params and path variables
params := matched.MatchGroups(target.Path)
for k, v := range matched.AssertQueryParamsPattern {
params[k] = v
}
for k, v := range target.AssertQueryParamsPattern {
params[k] = v
}
params[fuzz.RequestCount] = fmt.Sprintf("%d", requestCount)
out, err := fuzz.ParseTemplate("", []byte(matched.Predicate), params)
log.WithFields(log.Fields{
"Path": matched.Path,
"Name": matched.Name,
"Method": matched.Method,
"RequestCount": requestCount,
"Timestamp": matched.LastUsageTime,
"MatchedOutput": string(out),
"Error": err,
}).Debugf("matching predicate...")
return err != nil || string(out) == "true"
}