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
Support replacing tag in scenario name
  • Loading branch information
jcdietrich committed Nov 6, 2024
commit 9bffe4508f37c1158c15598565b3bc3e5fd7a8b6
4 changes: 4 additions & 0 deletions pkg/vars/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ func (fp ResponseMessageEvaluator) walkAndFill(res *mock.HTTPEntity, vars map[st

func (fp ResponseMessageEvaluator) walkAndGetScenario(scenario mock.Scenario) []string {
vars := []string{}
fp.extractVars(scenario.Name, &vars)

for _, value := range scenario.Values {
fp.extractVars(value, &vars)
}
Expand All @@ -106,6 +108,8 @@ func (fp ResponseMessageEvaluator) walkAndGetScenario(scenario mock.Scenario) []
func (fp ResponseMessageEvaluator) walkAndFillScenario(
scenario *mock.Scenario,
vars map[string][]string) {
scenario.Name = fp.replaceVars(scenario.Name, vars)

for valueName, value := range scenario.Values {
scenario.Values[valueName] = fp.replaceVars(value, vars)
}
Expand Down
27 changes: 27 additions & 0 deletions pkg/vars/evaluator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,33 @@ func TestReplaceTags(t *testing.T) {
}
}

func TestReplaceTagInScenarioName(t *testing.T) {
req := mock.Request{}
req.Body = "hi!"

val := make(mock.Values)
val["id"] = []string{"123454321:id:"}

req.QueryStringParameters = val

res := mock.Response{}
cb := mock.Callback{}
mock := mock.Definition{Request: req, Response: res, Callback: cb}
mock.Control.Scenario.Name = "scenarioName_{{request.query.id}}"

scenarioValues := make(map[string]string)
scenarioValues["tested"] = "ok"

storer := NewDummyScenarioStorer("scenarioName_{{request.query.id}}", scenarioValues)

varsProcessor := getProcessor()
varsProcessor.Eval(&req, &mock, storer)

if mock.Control.Scenario.Name != "scenarioName_123454321:id:" {
t.Error("Scenario name not updated", mock.Control.Scenario.Name)
}
}

func TestReplaceUndefinedFakeTag(t *testing.T) {
req := mock.Request{}
val := make(mock.Values)
Expand Down