-
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.
- Loading branch information
Showing
8 changed files
with
198 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
name: Run Tests | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
test: | ||
name: Run Tests | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Run tests | ||
run: ./test/test-results-to-csv.sh |
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
#!/bin/bash | ||
|
||
RESULTS_ROOT=/opt/speedtest-results | ||
RESULTS_ROOT=${1:-/opt/speedtest-results} | ||
|
||
echo "Date,Download (bytes/sec),Upload (bytes/sec),Ping Latency (ms)" > "$RESULTS_ROOT/../all_results.csv" | ||
|
||
for json in "$RESULTS_ROOT"/*.json; do | ||
cat $json | jq -r '(.timestamp|rtrimstr("Z")) + "," + (.download.bandwidth|tostring) + "," + (.upload.bandwidth|tostring) + "," + (.ping.latency|tostring)' >> /opt/all_results.csv; | ||
cat $json | jq -r '(.timestamp|rtrimstr("Z")) + "," + (.download.bandwidth|tostring) + "," + (.upload.bandwidth|tostring) + "," + (.ping.latency|tostring)' >> "$RESULTS_ROOT/../all_results.csv"; | ||
done |
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,3 @@ | ||
Date,Download (bytes/sec),Upload (bytes/sec),Ping Latency (ms) | ||
2024-06-08T13:17:33,29246873,26668973,6.846 | ||
2024-06-08T13:15:53,28921089,29686541,6.902 |
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,54 @@ | ||
{ | ||
"type": "result", | ||
"timestamp": "2024-06-08T13:17:33Z", | ||
"ping": { | ||
"jitter": 0.220, | ||
"latency": 6.846, | ||
"low": 6.535, | ||
"high": 6.946 | ||
}, | ||
"download": { | ||
"bandwidth": 29246873, | ||
"bytes": 155377640, | ||
"elapsed": 5305, | ||
"latency": { | ||
"iqm": 12.003, | ||
"low": 6.031, | ||
"high": 15.926, | ||
"jitter": 1.477 | ||
} | ||
}, | ||
"upload": { | ||
"bandwidth": 26668973, | ||
"bytes": 291554733, | ||
"elapsed": 12123, | ||
"latency": { | ||
"iqm": 33.250, | ||
"low": 5.704, | ||
"high": 37.299, | ||
"jitter": 2.640 | ||
} | ||
}, | ||
"isp": "Some ISP", | ||
"interface": { | ||
"internalIp": "1.2.3.4", | ||
"name": "tap0", | ||
"macAddr": "00:00:00:00:00:00", | ||
"isVpn": true, | ||
"externalIp": "42.42.42.42" | ||
}, | ||
"server": { | ||
"id": 44437, | ||
"host": "speedtest.foo.bar", | ||
"port": 8080, | ||
"name": "Foobar", | ||
"location": "Springfield", | ||
"country": "Moon", | ||
"ip": "42.42.42.42" | ||
}, | ||
"result": { | ||
"id": "some-uuid", | ||
"url": "https://www.speedtest.net/result/c/some-uuid", | ||
"persisted": true | ||
} | ||
} |
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,48 @@ | ||
{ | ||
"type": "result", | ||
"timestamp": "2024-06-08T13:15:53Z", | ||
"ping": { | ||
"jitter": 0.109, | ||
"latency": 6.902, | ||
"low": 6.692, | ||
"high": 7.036 | ||
}, | ||
"download": { | ||
"bandwidth": 28921089, | ||
"bytes": 167802928, | ||
"elapsed": 5800, | ||
"latency": { | ||
"iqm": 12.087, | ||
"low": 5.750, | ||
"high": 15.831, | ||
"jitter": 1.308 | ||
} | ||
}, | ||
"upload": { | ||
"bandwidth": 29686541, | ||
"bytes": 415039819, | ||
"elapsed": 15009 | ||
}, | ||
"isp": "Some ISP", | ||
"interface": { | ||
"internalIp": "1.2.3.4", | ||
"name": "tap0", | ||
"macAddr": "00:00:00:00:00:00", | ||
"isVpn": true, | ||
"externalIp": "42.42.42.42" | ||
}, | ||
"server": { | ||
"id": 44437, | ||
"host": "speedtest.foo.bar", | ||
"port": 8080, | ||
"name": "Foobar", | ||
"location": "Springfield", | ||
"country": "Moon", | ||
"ip": "42.42.42.42" | ||
}, | ||
"result": { | ||
"id": "some-uuid", | ||
"url": "https://www.speedtest.net/result/c/some-uuid", | ||
"persisted": true | ||
} | ||
} |
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,71 @@ | ||
#!/bin/bash | ||
|
||
if [ "$EUID" -eq 0 ]; then | ||
echo "This script must not be run as root." >&2 | ||
exit 1 | ||
fi | ||
|
||
EXIT_CODE=0 | ||
SCRIPT_DIR=$(dirname -- "$( readlink -f -- "$0"; )") | ||
|
||
|
||
function test_resulting_csv() { | ||
printf "\n== Test resulting csv ==\n" | ||
TEMP_DIR=$(mktemp -d) | ||
|
||
mkdir "$TEMP_DIR/jsons" | ||
cp "$SCRIPT_DIR"/resources/*.json "$TEMP_DIR/jsons" | ||
|
||
|
||
# Execute script under test | ||
bash "$SCRIPT_DIR"/../results-to-csv.sh "$TEMP_DIR/jsons" | ||
|
||
|
||
# Assertions | ||
if ! [ -f "$TEMP_DIR/all_results.csv" ]; then | ||
printf " Test failed - '$TEMP_DIR/all-results.json' not found\n" | ||
EXIT_CODE=1 | ||
fi | ||
|
||
if ! cmp -s "$TEMP_DIR/all_results.csv" "$SCRIPT_DIR"/resources/expeced.csv; then | ||
printf " Test failed - all_results.csv != $SCRIPT_DIR/resources/expeced.csv\n" | ||
EXIT_CODE=1 | ||
fi | ||
|
||
rm -rf "$TEMP_DIR" | ||
} | ||
|
||
|
||
function test_resulting_csv_if_error_file_is_there() { | ||
printf "\n== Test resulting csv if error json file available ==\n" | ||
TEMP_DIR=$(mktemp -d) | ||
|
||
mkdir "$TEMP_DIR/jsons" | ||
cp "$SCRIPT_DIR"/resources/*.json "$TEMP_DIR/jsons" | ||
printf "speedtest-error-result3.json" > "$TEMP_DIR/jsons/some-error.json" | ||
|
||
|
||
# Execute script under test | ||
bash "$SCRIPT_DIR"/../results-to-csv.sh "$TEMP_DIR/jsons" | ||
|
||
|
||
# Assertions | ||
if ! [ -f "$TEMP_DIR/all_results.csv" ]; then | ||
printf " Test failed - '$TEMP_DIR/all-results.json' not found\n" | ||
EXIT_CODE=1 | ||
fi | ||
|
||
if ! cmp -s "$TEMP_DIR/all_results.csv" "$SCRIPT_DIR"/resources/expeced.csv; then | ||
printf " Test failed - all_results.csv != $SCRIPT_DIR/resources/expeced.csv\n" | ||
EXIT_CODE=1 | ||
fi | ||
|
||
rm -rf "$TEMP_DIR" | ||
} | ||
|
||
|
||
|
||
test_resulting_csv | ||
test_resulting_csv_if_error_file_is_there | ||
|
||
exit "$EXIT_CODE" |