Add mock-response property

pull/624/merge
Svilen Markov 2025-08-06 04:35:55 +07:00
parent 44804debd6
commit f0d0b9f1ba
1 changed files with 11 additions and 0 deletions

@ -11,6 +11,7 @@ import (
"iter" "iter"
"log/slog" "log/slog"
"math" "math"
"math/rand"
"net/http" "net/http"
"regexp" "regexp"
"sort" "sort"
@ -33,6 +34,7 @@ type CustomAPIRequest struct {
Method string `yaml:"method"` Method string `yaml:"method"`
BodyType string `yaml:"body-type"` BodyType string `yaml:"body-type"`
Body any `yaml:"body"` Body any `yaml:"body"`
MockResponse string `yaml:"mock-response"`
SkipJSONValidation bool `yaml:"skip-json-validation"` SkipJSONValidation bool `yaml:"skip-json-validation"`
bodyReader io.ReadSeeker `yaml:"-"` bodyReader io.ReadSeeker `yaml:"-"`
httpRequest *http.Request `yaml:"-"` httpRequest *http.Request `yaml:"-"`
@ -230,6 +232,15 @@ func (data *customAPITemplateData) Subrequest(key string) *customAPIResponseData
} }
func fetchCustomAPIResponse(ctx context.Context, req *CustomAPIRequest) (*customAPIResponseData, error) { func fetchCustomAPIResponse(ctx context.Context, req *CustomAPIRequest) (*customAPIResponseData, error) {
if req != nil && req.MockResponse != "" {
return &customAPIResponseData{
JSON: decoratedGJSONResult{gjson.Parse(req.MockResponse)},
Response: &http.Response{
StatusCode: http.StatusOK,
},
}, nil
}
if req == nil || req.URL == "" { if req == nil || req.URL == "" {
return &customAPIResponseData{ return &customAPIResponseData{
JSON: decoratedGJSONResult{gjson.Result{}}, JSON: decoratedGJSONResult{gjson.Result{}},