From 2a6d88bc39f6d977986628fbc2e5d0e9396ecc4c Mon Sep 17 00:00:00 2001 From: Markus Opolka Date: Wed, 9 Apr 2025 16:57:17 +0200 Subject: [PATCH] Add testdata to simplify integration testing --- test/testdata/README.md | 63 ++++++++++++++++++++++++++++++++ test/testdata/data0-invalid.json | 1 + test/testdata/data1.json | 5 +++ test/testdata/data2.json | 17 +++++++++ test/testdata/data3.json | 18 +++++++++ test/testdata/data4.json | 13 +++++++ test/testdata/data5.json | 38 +++++++++++++++++++ test/testdata/docker-compose.yml | 7 ++++ 8 files changed, 162 insertions(+) create mode 100644 test/testdata/README.md create mode 100644 test/testdata/data0-invalid.json create mode 100644 test/testdata/data1.json create mode 100644 test/testdata/data2.json create mode 100644 test/testdata/data3.json create mode 100644 test/testdata/data4.json create mode 100644 test/testdata/data5.json create mode 100644 test/testdata/docker-compose.yml diff --git a/test/testdata/README.md b/test/testdata/README.md new file mode 100644 index 0000000..a563ac8 --- /dev/null +++ b/test/testdata/README.md @@ -0,0 +1,63 @@ +# Example Data for Testing + +Example calls: + +```bash +python check_http_json.py -H localhost:8080 -p data0.json -q "age,20" +UNKNOWN: Status UNKNOWN. Could not find JSON in HTTP body. +``` + +```bash +python check_http_json.py -H localhost:8080 -p data1.json -e date +WARNING: Status WARNING. Key date did not exist. + +python check_http_json.py -H localhost:8080 -p data1.json -E age +OK: Status OK. + +python check_http_json.py -H localhost:8080 -p data1.json -w "age,30" +OK: Status OK. + +python check_http_json.py -H localhost:8080 -p data1.json -w "age,20" +WARNING: Status WARNING. Value (30) for key age was outside the range 0:20. + +python check_http_json.py -H localhost:8080 -p data1.json -q "age,20" +WARNING: Status WARNING. Key age mismatch. 20 != 30 +``` + +```bash +python check_http_json.py -H localhost:8080 -p data2.json -q "(1).id,123" +WARNING: Status WARNING. Key (1).id mismatch. 123 != 2 + +python check_http_json.py -H localhost:8080 -p data2.json -Y "(1).id,2" +CRITICAL: Status CRITICAL. Key (1).id match found. 2 == 2 + +python check_http_json.py -H localhost:8080 -p data2.json -E "(1).author" +OK: Status OK. + +python check_http_json.py -H localhost:8080 -p data2.json -E "(1).pages" +CRITICAL: Status CRITICAL. Key (1).pages did not exist. +``` + +```bash +python check_http_json.py -H localhost:8080 -p data3.json -q "company.employees.(0).role,Developer" +OK: Status OK. + +python check_http_json.py -H localhost:8080 -p data3.json -q "company.employees.(0).role,Dev" +WARNING: Status WARNING. Key company.employees.(0).role mismatch. Dev != Developer + +python check_http_json.py -H localhost:8080 -p data3.json -q "company.employees.(0).role,Developer" "company.employees.(1).role,Designer" +OK: Status OK. +``` + +```bash +python check_http_json.py -H localhost:8080 -p data4.json -u "ratings(0),4.5" +OK: Status OK. + +python check_http_json.py -H localhost:8080 -p data4.json -u "ratings(0),4.1" +UNKNOWN: Status UNKNOWN. Key ratings(0) mismatch. 4.1 != 4.5 +``` + +```bash +python check_http_json.py -H localhost:8080 -p data5.json -q service1.status,True service2.status,True service3.status,True +OK: Status OK. +``` diff --git a/test/testdata/data0-invalid.json b/test/testdata/data0-invalid.json new file mode 100644 index 0000000..11dcdb1 --- /dev/null +++ b/test/testdata/data0-invalid.json @@ -0,0 +1 @@ +No JSON diff --git a/test/testdata/data1.json b/test/testdata/data1.json new file mode 100644 index 0000000..cf7fb75 --- /dev/null +++ b/test/testdata/data1.json @@ -0,0 +1,5 @@ +{ + "name": "John Doe", + "age": 30, + "city": "New York" +} diff --git a/test/testdata/data2.json b/test/testdata/data2.json new file mode 100644 index 0000000..a5c9dcd --- /dev/null +++ b/test/testdata/data2.json @@ -0,0 +1,17 @@ +[ + { + "id": 1, + "title": "Book One", + "author": "Author One" + }, + { + "id": 2, + "title": "Book Two", + "author": "Author Two" + }, + { + "id": 3, + "title": "Book Three", + "author": "Author Three" + } +] diff --git a/test/testdata/data3.json b/test/testdata/data3.json new file mode 100644 index 0000000..dfde663 --- /dev/null +++ b/test/testdata/data3.json @@ -0,0 +1,18 @@ +{ + "company": { + "name": "Tech Corp", + "location": "San Francisco", + "employees": [ + { + "name": "Alice", + "role": "Developer" + }, + { + "name": "Bob", + "role": "Designer" + } + ] + }, + "founded": 2010, + "industry": "Technology" +} diff --git a/test/testdata/data4.json b/test/testdata/data4.json new file mode 100644 index 0000000..6524bff --- /dev/null +++ b/test/testdata/data4.json @@ -0,0 +1,13 @@ +{ + "id": 123, + "active": true, + "tags": ["tech", "startup", "innovation"], + "details": { + "website": "https://example.com", + "contact": { + "email": "info@example.com", + "phone": "+1-234-567-890" + } + }, + "ratings": [4.5, 4.7, 4.8] +} diff --git a/test/testdata/data5.json b/test/testdata/data5.json new file mode 100644 index 0000000..c10a7ab --- /dev/null +++ b/test/testdata/data5.json @@ -0,0 +1,38 @@ +{ + "service1": { + "status": true + }, + "service2": { + "status": true, + "meta": { + "res": "PONG" + } + }, + "service3": { + "status": true, + "meta": { + "took": 9, + "timed_out": false, + "_shards": { + "total": 0, + "successful": 0, + "skipped": 0, + "failed": 0 + }, + "hits": { + "total": { + "value": 10000, + "relation": "gte" + }, + "max_score": null, + "hits": [] + } + } + }, + "service4": { + "status": true, + "meta": { + "status": "ok" + } + } +} diff --git a/test/testdata/docker-compose.yml b/test/testdata/docker-compose.yml new file mode 100644 index 0000000..cc3fab0 --- /dev/null +++ b/test/testdata/docker-compose.yml @@ -0,0 +1,7 @@ +services: + nginx: + image: nginx:1-alpine + ports: + - "8080:80" + volumes: + - ./:/usr/share/nginx/html