Add test for JSON export

This commit is contained in:
nicolargo
2025-06-01 17:37:21 +02:00
parent fe5edd6e60
commit a6de55bfca
3 changed files with 25 additions and 5 deletions

View File

@@ -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

View File

@@ -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

19
tests/test_export_json.sh Executable file
View File

@@ -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