Skip to content

Commit

Permalink
update default value of regex; pring error if lua script is malformed
Browse files Browse the repository at this point in the history
  • Loading branch information
wallyatgithub committed Nov 1, 2022
1 parent 591095e commit 5c3c8ed
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
9 changes: 5 additions & 4 deletions config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@
"enum": ["EqualsTo", "StartsWith", "EndsWith", "Contains", "RegexMatch"]
},
"input":{
"description": "Content used to run the matchType above against the received header value; i.e., received header value should either equal to or start with or end with or contain the content specified in this field; if RegexMatch is chosen, it means this input field is a regular expression in ECMAScript grammar, and it should match the entire target character sequence, i.e., the header value",
"description": "Content used to run the matchType above against the received header value; i.e., received header value should either equal to or start with or end with or contain the content specified in this field; if RegexMatch is chosen, it means this input field is a regular expression of ECMAScript flavor, and it should match the entire target character sequence, i.e., the header value",
"default": "200",
"type":"string"
}
Expand All @@ -489,7 +489,7 @@
"enum": ["EqualsTo", "StartsWith", "EndsWith", "Contains", "RegexMatch"]
},
"input": {
"description": "Content used to execute the matchType above against the value specified by the Json pointer above; the value specified by the Json pointer above should either equal to or start with or end with or contain the content specified in this field; if RegexMatch is chosen, it means this input field is a regular expression in ECMAScript grammar, and it should match the entire target character sequence, i.e., the value specified by the Json pointer",
"description": "Content used to execute the matchType above against the value specified by the Json pointer above; the value specified by the Json pointer above should either equal to or start with or end with or contain the content specified in this field; if RegexMatch is chosen, it means this input field is a regular expression of ECMAScript flavor, and it should match the entire target character sequence, i.e., the value specified by the Json pointer",
"type":"string"
}
}
Expand All @@ -499,7 +499,7 @@
},
"value-pickers":
{
"description": "This is the actions to run when the response is received; it is using a regular expression to pick up a value, from a specific header, or from a value in the payload specified by a Json pointer, and then save the value to a variable whose name is given in save-to-variable; the stored value can be accessed later by wrapping the name of the variable with ${}, for example, pick up a value from the response header here, and store it to a variable named user_id, and then refer to this variable in a later request of the same scenario in this way: some_api_path/${user_id}, and ${user_id} would be replaced by the actual value stored here",
"description": "This is the actions to run when the response is received; it is using a regular expression of ECMAScript flavor to pick up a value, from a specific header, or from a value in the payload specified by a Json pointer, and then save the value to a variable whose name is given in save-to-variable; the stored value can be accessed later by wrapping the name of the variable with ${}, for example, pick up a value from the response header here, and store it to a variable named user_id, and then refer to this variable in a later request of the same scenario in this way: some_api_path/${user_id}, and ${user_id} would be replaced by the actual value stored here",
"type": "array",
"items": {
"type": "object",
Expand All @@ -515,7 +515,8 @@
"description": "A header name, or a Json pointer, depending on what is given in where-to-pickup-from"
},
"regexp": {
"description": "A regular expression to extract value from the source above",
"description": "A regular expression of ECMAScript flavor to extract value from the source above",
"default": ".*",
"type":"string"
},
"save-to-variable": {
Expand Down
11 changes: 10 additions & 1 deletion h2load_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1536,8 +1536,9 @@ void post_process_json_config_schema(h2load::Config& config)

for (auto& scenario : config.json_config_schema.scenarios)
{
for (auto& request : scenario.requests)
for (auto i = 0; i < scenario.requests.size(); i++)
{
auto& request = scenario.requests[i];

for (auto& schema_header_match : request.response_match.header_match)
{
Expand All @@ -1561,12 +1562,20 @@ void post_process_json_config_schema(h2load::Config& config)
{
request.make_request_function_present = true;
}
else
{
std::cerr << scenario.name<<"_"<<i<<": lua script provided, but function " << make_request <<" is either malformed, or not present"<<std::endl;
}
lua_settop(L, 0);
lua_getglobal(L, validate_response);
if (lua_isfunction(L, -1))
{
request.validate_response_function_present = true;
}
else
{
std::cerr << scenario.name<<"_"<<i<<": lua script provided, but function " << validate_response <<" is either malformed, or not present"<<std::endl;
}
lua_settop(L, 0);
lua_close(L);
}
Expand Down

0 comments on commit 5c3c8ed

Please sign in to comment.