|
- #!/bin/bash
- # Full API smoke test: Creates, lists, updates, and deletes records
- # effectively exercising 100% of the routes defined in routes.go.
- #
- # Requires: jq
- # Usage: ./smoke_test.sh
-
- set -e
-
- # Imposta l'URL di default sulla porta corretta del container esposto (1902)
- BASE_URL=${BASE_URL:-"http://127.0.0.1:1902"}
-
- # Generiamo degli UUID statici di test validi per la sessione dello script
- GTW_UUID="11111111-2222-3333-4444-555555555555"
- ZONE_UUID="22222222-3333-4444-5555-666666666666"
- TRK_UUID="33333333-4444-5555-6666-777777777777"
- FLR_UUID="44444444-5555-6666-7777-888888888888"
-
- echo "=========================================="
- echo "STARTING SYSTEM HEALTH CHECKS"
- echo "=========================================="
-
- echo -n "Checking basic /health... "
- curl -s -f -X GET "$BASE_URL/health" && echo "OK" || (echo "FAILED"; exit 1)
-
- echo -n "Checking database readiness /ready... "
- curl -s -f -X GET "$BASE_URL/ready" && echo "OK" || (echo "FAILED"; exit 1)
-
- echo -n "Checking application state /reslevis/health... "
- curl -s -f -X GET "$BASE_URL/reslevis/health" && echo "OK" || (echo "FAILED"; exit 1)
-
- sleep 1
-
- # ---------------------------------------------------------------------------
- # GATEWAYS
- # ---------------------------------------------------------------------------
- echo -e "\n=========================================="
- echo "GATEWAY API TESTS"
- echo "=========================================="
-
- echo "1. Creating a test Gateway (POST)"
- curl -s -X POST "$BASE_URL/reslevis/postGateway" \
- -H "Content-Type: application/json" \
- -d "{\"id\": \"$GTW_UUID\", \"name\": \"GTW-SMOKE-01\", \"mac\": \"AA:BB:CC:00:11:22\", \"status\": \"online\", \"model\": \"MG3\", \"ip\": \"192.168.1.50\"}"
- echo -e "\n"
-
- echo "2. Listing Gateways"
- curl -s -X GET "$BASE_URL/reslevis/getGateways" | jq '.'
-
- echo -e "\n3. Updating Gateway (PUT)"
- curl -s -X PUT "$BASE_URL/reslevis/updateGateway/$GTW_UUID" \
- -H "Content-Type: application/json" \
- -d "{\"id\": \"$GTW_UUID\", \"name\": \"GTW-SMOKE-UPDATED\", \"mac\": \"AA:BB:CC:00:11:22\", \"status\": \"online\", \"model\": \"MG3\", \"ip\": \"192.168.1.51\"}"
- echo -e "\n"
-
- echo "4. Removing Gateway (DELETE)"
- curl -s -X DELETE "$BASE_URL/reslevis/removeGateway/$GTW_UUID"
- echo -e "\n"
-
- # ---------------------------------------------------------------------------
- # ZONES
- # ---------------------------------------------------------------------------
- echo -e "\n=========================================="
- echo "ZONE API TESTS"
- echo "=========================================="
-
- echo "5. Creating a test Zone (POST)"
- curl -s -X POST "$BASE_URL/reslevis/postZone" \
- -H "Content-Type: application/json" \
- -d "{\"id\": \"$ZONE_UUID\", \"name\": \"Zone-Smoke-Test\", \"groups\": [\"test\"]}"
- echo -e "\n"
-
- echo "6. Listing Zones"
- curl -s -X GET "$BASE_URL/reslevis/getZones" | jq '.'
-
- echo -e "\n7. Updating Zone (PUT)"
- curl -s -X PUT "$BASE_URL/reslevis/updateZone" \
- -H "Content-Type: application/json" \
- -d "{\"id\": \"$ZONE_UUID\", \"name\": \"Zone-Smoke-Updated\", \"groups\": [\"test\", \"updated\"]}"
- echo -e "\n"
-
- echo "8. Removing Zone (DELETE)"
- curl -s -X DELETE "$BASE_URL/reslevis/removeZone/$ZONE_UUID"
- echo -e "\n"
-
- # ---------------------------------------------------------------------------
- # TRACKERS
- # ---------------------------------------------------------------------------
- echo -e "\n=========================================="
- echo "TRACKER API TESTS"
- echo "=========================================="
-
- echo "9. Creating a test Tracker (POST)"
- # I valori dei campi battery e temperature sono passati come stringhe ("99", "24")
- # per soddisfare la configurazione Go `validate:"required"` e il tag `,string` delle struct.
- curl -s -X POST "$BASE_URL/reslevis/postTracker" \
- -H "Content-Type: application/json" \
- -d "{\"id\": \"$TRK_UUID\", \"name\": \"TRK-SMOKE\", \"mac\": \"00:11:22:33:44:55\", \"status\": \"online\", \"battery\": \"99\", \"temperature\": \"24\"}"
- echo -e "\n"
-
- echo "10. Listing Trackers"
- curl -s -X GET "$BASE_URL/reslevis/getTrackers" | jq '.'
-
- echo -e "\n11. Updating Tracker (PUT)"
- curl -s -X PUT "$BASE_URL/reslevis/updateTracker" \
- -H "Content-Type: application/json" \
- -d "{\"id\": \"$TRK_UUID\", \"name\": \"TRK-SMOKE-UPDATED\", \"mac\": \"00:11:22:33:44:55\", \"status\": \"offline\", \"battery\": \"80\", \"temperature\": \"22\"}"
- echo -e "\n"
-
- echo "12. Removing Tracker (DELETE)"
- curl -s -X DELETE "$BASE_URL/reslevis/removeTracker/$TRK_UUID"
- echo -e "\n"
-
- # ---------------------------------------------------------------------------
- # FLOORS
- # ---------------------------------------------------------------------------
- echo -e "\n=========================================="
- echo "FLOOR API TESTS"
- echo "=========================================="
-
- echo "13. Creating a test Floor (POST)"
- curl -s -X POST "$BASE_URL/reslevis/postFloor" \
- -H "Content-Type: application/json" \
- -d "{\"id\": \"$FLR_UUID\", \"name\": \"Floor 1\", \"floornumber\": 1, \"image\": \"\", \"description\": \"Test\", \"scale\": 1, \"building\": \"Main\"}"
- echo -e "\n"
-
- echo "14. Listing Floors"
- curl -s -X GET "$BASE_URL/reslevis/getFloors" | jq '.'
-
- echo -e "\n15. Removing Floor (DELETE)"
- curl -s -X DELETE "$BASE_URL/reslevis/removeFloor/$FLR_UUID"
- echo -e "\n"
-
- # ---------------------------------------------------------------------------
- # PARSER CONFIGS & SETTINGS
- # ---------------------------------------------------------------------------
- echo "=========================================="
- echo "PARSER CONFIGS & SETTINGS TESTS"
- echo "=========================================="
-
- echo "16. Listing Parser Beacons configurations"
- curl -s -X GET "$BASE_URL/configs/beacons" | jq '.'
-
- echo -e "\n17. Testing Settings GET"
- curl -s -X GET "$BASE_URL/reslevis/settings" | jq '.'
-
- echo -e "\n=========================================="
- echo "ALL TESTS COMPLETED"
- echo "=========================================="
|