From a6de55bfcaa0f656a294aa92b615a06c1d6f56e4 Mon Sep 17 00:00:00 2001 From: nicolargo Date: Sun, 1 Jun 2025 17:37:21 +0200 Subject: [PATCH] Add test for JSON export --- Makefile | 5 ++++- tests/test_export_csv.sh | 6 ++---- tests/test_export_json.sh | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) create mode 100755 tests/test_export_json.sh diff --git a/Makefile b/Makefile index d71604e0..8d010e5d 100644 --- a/Makefile +++ b/Makefile @@ -117,13 +117,16 @@ test-min-with-upgrade: venv-min-upgrade ## Upgrade deps and run unit tests in mi test-export-csv: ## Run interface tests with CSV /bin/bash ./tests/test_export_csv.sh +test-export-json: ## Run interface tests with JSON + /bin/bash ./tests/test_export_json.sh + test-export-influxdb-v1: ## Run interface tests with InfluxDB version 1 (Legacy) /bin/bash ./tests/test_export_influxdb_v1.sh test-export-influxdb-v3: ## Run interface tests with InfluxDB version 3 (Core) /bin/bash ./tests/test_export_influxdb_v3.sh -test-export: test-export-csv test-export-influxdb-v1 test-export-influxdb-v3 ## Tests all exports +test-export: test-export-csv test-export-json test-export-influxdb-v1 test-export-influxdb-v3 ## Tests all exports # =================================================================== # Linters, profilers and cyber security diff --git a/tests/test_export_csv.sh b/tests/test_export_csv.sh index 1a51b4c8..193cd7b3 100755 --- a/tests/test_export_csv.sh +++ b/tests/test_export_csv.sh @@ -1,15 +1,13 @@ #!/bin/bash -# Pre-requisites: -# - jq # Exit on error set -e -# Run glances with export to InfluxDB, stopping after 10 writes +# Run glances with export to CSV file, stopping after 10 writes # This will run synchronously now since we're using --stop-after echo "Glances starts to export system stats to CSV file /tmp/glances.csv (duration: ~ 20 seconds)" rm -f /tmp/glances.csv ./venv/bin/python -m glances --export csv --export-csv-file /tmp/glances.csv --stop-after 10 --quiet echo "Checking CSV file..." -./venv/bin/python ./tests-data/tools/csvcheck.py -i /tmp/glances2.csv -l 9 +./venv/bin/python ./tests-data/tools/csvcheck.py -i /tmp/glances.csv -l 9 diff --git a/tests/test_export_json.sh b/tests/test_export_json.sh new file mode 100755 index 00000000..75236a25 --- /dev/null +++ b/tests/test_export_json.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Exit on error +set -e + +# Run glances with export to JSON file, stopping after 3 writes (to be sure rates are included) +# This will run synchronously now since we're using --stop-after +echo "Glances starts to export system stats to JSON file /tmp/glances.json (duration: ~ 10 seconds)" +rm -f /tmp/glances.json +./venv/bin/python -m glances --export json --export-json-file /tmp/glances.json --stop-after 3 --quiet + +echo "Checking JSON file..." +jq . /tmp/glances.json +jq .cpu /tmp/glances.json +jq .cpu.total /tmp/glances.json +jq .mem /tmp/glances.json +jq .mem.total /tmp/glances.json +jq .processcount /tmp/glances.json +jq .processcount.total /tmp/glances.json