Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ If, for example, you want to run only your UI tests ending with `ui`, you can ac
./http-api-tester -g ".*ui$" example-suite
```

### Comparing with greater-or-equal

This option was introduced to cope with changing (growing) timestamps that may be part of your json answer.
```sh
./http-api-tester -o ge example-suite-ge/
```

## Installation

Make sure to have your test suites ready in your project directory and the requirements set up. To run the tool, just execute:
Expand Down
2 changes: 2 additions & 0 deletions example-suite-ge/after-all
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
echo " - starting something needed for all test cases"
2 changes: 2 additions & 0 deletions example-suite-ge/after-each
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
echo " - do something after each test"
2 changes: 2 additions & 0 deletions example-suite-ge/before-all
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
echo " - do something before each test"
2 changes: 2 additions & 0 deletions example-suite-ge/before-each
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
echo " - do something before each test"
1 change: 1 addition & 0 deletions example-suite-ge/greater-equal-compare/curl-options
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-k
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
200
4 changes: 4 additions & 0 deletions example-suite-ge/greater-equal-compare/expected/response-data
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"b" : [1, 2],
"a" : 24
}
23 changes: 23 additions & 0 deletions example-suite-ge/greater-equal-compare/expected/response-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[
{
"id": "http-server",
"description": "A simple Python HTTP request handler. This class serves files from the current directory and below, directly mapping the directory structure to HTTP requests.",
"parameters": [
"id"
]
},
{
"id": "jupyter",
"description": "Open source, interactive data science and scientific computing across over 40 programming languages.",
"parameters": [
"id"
]
},
{
"id": "zeppelin",
"description": "A web-based notebook that enables interactive data analytics.\nYou can make beautiful data-driven, interactive and collaborative documents with SQL, Scala and more.",
"parameters": [
"id"
]
}
]
1 change: 1 addition & 0 deletions example-suite-ge/greater-equal-compare/method
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GET
Empty file.
2 changes: 2 additions & 0 deletions example-suite-ge/greater-equal-compare/request-header
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
X-MyHeader: 123
X-YourHeader: 321
4 changes: 4 additions & 0 deletions example-suite-ge/greater-equal-compare/response-data.actual
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"a" : 42,
"b" : [1, 2]
}
1 change: 1 addition & 0 deletions example-suite-ge/greater-equal-compare/url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
localhost:8080/example-suite-ge/greater-equal-compare/response-data.actual
7 changes: 7 additions & 0 deletions example-suite-ge/response-date.actual
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"b": [
1,
2
],
"a": 42
}
1 change: 1 addition & 0 deletions example-suite/correct-json-content/curl-options
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-k
26 changes: 24 additions & 2 deletions http-api-tester
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ function print_usage {
echo " show diff in case of test failure"
echo " -g|--grep \"<regex>\""
echo " only execute test cases matching the regex"
echo " -o|--operand \"<eq|ge|le>\""
echo " match equal, greater-or-equal than, or less-or-equal than (in jq comparison of json)"
if [ -z "$1" ]; then
exit 1
else
Expand Down Expand Up @@ -41,6 +43,10 @@ while [[ $# -gt 1 ]]; do
grep=$2
shift 1
;;
-o|--operand)
operand=$2
shift 1
;;
*)
print_usage
;;
Expand Down Expand Up @@ -92,6 +98,11 @@ function test {
return
fi

if [[ -z $operand ]] ; then
operand=eq
fi
echo -e " comparison uses operand $operand"

echo -e " \033[1m$run_folder\033[0m:"

if [ ! -z "$clean" ]; then
Expand Down Expand Up @@ -164,8 +175,19 @@ function test {
function compare {
local actual="$actual_folder/$1"
local expected="$expected_folder/$1"
jq -e --argfile actual $actual --argfile expected $expected -n '$actual == $expected' > /dev/null
local status=$?
if [ $operand == "eq" ]; then
jq -e --argfile actual $actual --argfile expected $expected -n '$actual == $expected' > /dev/null
local status=$?
elif [ $operand == "ge" ]; then
jq -e --argfile actual $actual --argfile expected $expected -n '$actual >= $expected' > /dev/null
local status=$?
elif [ $operand == "le" ]; then
jq -e --argfile actual $actual --argfile expected $expected -n '$actual <= $expected' > /dev/null
local status=$?
else
echo "Don't know what to do with operand $operand, exiting";
exit 2
fi
if [ $status -ne 0 ]; then
echo -e " - \033[0;31m$actual did not match $expected\033[0m" >&2
if [ ! -z "$detail" ]; then
Expand Down