Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scenario Values & Reading from Response #178

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Prev Previous commit
Next Next commit
fix scenario value lookup, add holder lookup for callback post stream
  • Loading branch information
jcdietrich committed Nov 6, 2024
commit 9b2e37cab62996e0a73650299c8292b86d39bdea
4 changes: 3 additions & 1 deletion pkg/mock/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

type Values map[string][]string

type ScenarioValues map[string]string

type Cookies map[string]string

type HttpHeaders struct {
Expand Down Expand Up @@ -47,7 +49,7 @@ type Callback struct {

type Scenario struct {
Name string `json:"name"`
Values map[string]string `json:"values"`
Values ScenarioValues `json:"values"`
RequiredState []string `json:"requiredState"`
NewState string `json:"newState"`
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/vars/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ func (fp ResponseMessageEvaluator) Eval(req *mock.Request, m *mock.Definition, s

//first replace the external streams
holders := fp.walkAndGet(m.Response.HTTPEntity)
holders = append(holders, fp.walkAndGet(m.Callback.HTTPEntity)...)

//fill holders with the correct values
vars := streamFiller.Fill(holders)
fp.walkAndFill(&m.Response.HTTPEntity, vars)
fp.walkAndFill(&m.Callback.HTTPEntity, vars)
Expand All @@ -45,6 +48,7 @@ func (fp ResponseMessageEvaluator) Eval(req *mock.Request, m *mock.Definition, s
vars = requestFiller.Fill(holders)
fp.mergeVars(vars, fakeFiller.Fill(holders))

// if we have a scenario, fill any scenario.* holders
if m.Control.Scenario.Name != "" {
scenarioFiller := fp.FillerFactory.CreateScenarioFiller(req, m, store, m.Control.Scenario.Name)
fp.mergeVars(vars, scenarioFiller.Fill(holders))
Expand Down Expand Up @@ -107,6 +111,7 @@ func (fp ResponseMessageEvaluator) replaceVars(input string, vars map[string][]s

func (fp ResponseMessageEvaluator) extractVars(input string, vars *[]string) {
if m := varsRegex.FindAllString(input, -1); m != nil {

for _, v := range m {
varName := strings.Trim(v, "{} ")
*vars = append(*vars, varName)
Expand Down
3 changes: 2 additions & 1 deletion pkg/vars/scenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ func (sf ScenarioFiller) Fill(holders []string) map[string][]string {
for _, tag := range holders {
found := false
s := ""

if strings.HasPrefix(tag, "scenario.") {
s, found = sf.Store.GetStateValue(sf.Name, tag[8:])
s, found = sf.Store.GetStateValue(sf.Name, tag[9:])
}

if found {
Expand Down