forked from stoplightio/prism
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): support global delay range
- Loading branch information
Showing
6 changed files
with
161 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
====test==== | ||
Given I mock and specify a constant delay | ||
When I send a request to an operation | ||
Then the response should be delayed by that amount | ||
====spec==== | ||
openapi: "3.1.0" | ||
info: | ||
version: "0.0" | ||
title: Config Test | ||
paths: | ||
/pets/{petId}: | ||
get: | ||
description: Get a pet by ID | ||
responses: | ||
"200": | ||
description: A pet | ||
content: | ||
application/json: | ||
schema: | ||
type: integer | ||
default: 0 | ||
====config==== | ||
{ | ||
"delay": 500 | ||
} | ||
====server==== | ||
mock -p 4010 --config ${config} ${document} | ||
====command==== | ||
curl -i -s -w "%{time_total}" "http://127.0.0.1:4010/pets/2" | awk '{gsub(/0([0-9]+\.[0-9]+)/, $1 * 1000 > 500 ? "Value is higher than 500" : "Value is not higher than 500"); print}' | ||
====expect-loose==== | ||
HTTP/1.1 200 OK | ||
|
||
Value is higher than 500 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
====test==== | ||
Given I mock and specify a constant delay | ||
When I send a request to an operation | ||
Then the response should be delayed by that amount | ||
====spec==== | ||
openapi: "3.1.0" | ||
info: | ||
version: "0.0" | ||
title: Config Test | ||
paths: | ||
/pets/{petId}: | ||
get: | ||
description: Get a pet by ID | ||
responses: | ||
"200": | ||
description: A pet | ||
content: | ||
application/json: | ||
schema: | ||
type: integer | ||
default: 0 | ||
====config==== | ||
{ | ||
"delay": [300, 500] | ||
} | ||
====server==== | ||
mock -p 4010 --config ${config} ${document} | ||
====command==== | ||
curl -i -s -w "%{time_total}" "http://127.0.0.1:4010/pets/2" | awk '{gsub(/0([0-9]+\.[0-9]+)/, $1 * 1000 > 300 ? "Value is higher than 300" : "Value is not higher than 300"); print}' | ||
====expect-loose==== | ||
HTTP/1.1 200 OK | ||
|
||
Value is higher than 300 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
====test==== | ||
When I send a request to an operation | ||
And I have a config with a delay of 2500ms | ||
And in the headers I specify `Prefer: delay=100` | ||
Then I get a response with a delay of 100ms | ||
====spec==== | ||
openapi: "3.1.1" | ||
info: | ||
version: "0" | ||
title: Delays test | ||
description: Delays test | ||
paths: | ||
/delay: | ||
get: | ||
description: widget details | ||
responses: | ||
"200": | ||
description: delay response | ||
content: | ||
application/json: | ||
schema: | ||
type: integer | ||
default: 0 | ||
====config==== | ||
{ | ||
"delay": 2500 | ||
} | ||
====server==== | ||
mock -p 4010 ${document} | ||
====command==== | ||
curl -i -s -w "%{time_total}" -H "Prefer: delay=100" "http://127.0.0.1:4010/delay" | awk '{gsub(/0([0-9]+\.[0-9]+)/, ($1 * 1000 < 2500 ? "Value is lower than 2500" : "Value is higher than 2500")); print}' | ||
====expect-loose==== | ||
HTTP/1.1 200 OK | ||
|
||
Value is lower than 2500 |