選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 

150 行
5.8 KiB

  1. #!/bin/bash
  2. # Full API smoke test: Creates, lists, updates, and deletes records
  3. # effectively exercising 100% of the routes defined in routes.go.
  4. #
  5. # Requires: jq
  6. # Usage: ./smoke_test.sh
  7. set -e
  8. # Imposta l'URL di default sulla porta corretta del container esposto (1902)
  9. BASE_URL=${BASE_URL:-"http://127.0.0.1:1902"}
  10. # Generiamo degli UUID statici di test validi per la sessione dello script
  11. GTW_UUID="11111111-2222-3333-4444-555555555555"
  12. ZONE_UUID="22222222-3333-4444-5555-666666666666"
  13. TRK_UUID="33333333-4444-5555-6666-777777777777"
  14. FLR_UUID="44444444-5555-6666-7777-888888888888"
  15. echo "=========================================="
  16. echo "STARTING SYSTEM HEALTH CHECKS"
  17. echo "=========================================="
  18. echo -n "Checking basic /health... "
  19. curl -s -f -X GET "$BASE_URL/health" && echo "OK" || (echo "FAILED"; exit 1)
  20. echo -n "Checking database readiness /ready... "
  21. curl -s -f -X GET "$BASE_URL/ready" && echo "OK" || (echo "FAILED"; exit 1)
  22. echo -n "Checking application state /reslevis/health... "
  23. curl -s -f -X GET "$BASE_URL/reslevis/health" && echo "OK" || (echo "FAILED"; exit 1)
  24. sleep 1
  25. # ---------------------------------------------------------------------------
  26. # GATEWAYS
  27. # ---------------------------------------------------------------------------
  28. echo -e "\n=========================================="
  29. echo "GATEWAY API TESTS"
  30. echo "=========================================="
  31. echo "1. Creating a test Gateway (POST)"
  32. curl -s -X POST "$BASE_URL/reslevis/postGateway" \
  33. -H "Content-Type: application/json" \
  34. -d "{\"id\": \"$GTW_UUID\", \"name\": \"GTW-SMOKE-01\", \"mac\": \"AA:BB:CC:00:11:22\", \"status\": \"online\", \"model\": \"MG3\", \"ip\": \"192.168.1.50\"}"
  35. echo -e "\n"
  36. echo "2. Listing Gateways"
  37. curl -s -X GET "$BASE_URL/reslevis/getGateways" | jq '.'
  38. echo -e "\n3. Updating Gateway (PUT)"
  39. curl -s -X PUT "$BASE_URL/reslevis/updateGateway/$GTW_UUID" \
  40. -H "Content-Type: application/json" \
  41. -d "{\"id\": \"$GTW_UUID\", \"name\": \"GTW-SMOKE-UPDATED\", \"mac\": \"AA:BB:CC:00:11:22\", \"status\": \"online\", \"model\": \"MG3\", \"ip\": \"192.168.1.51\"}"
  42. echo -e "\n"
  43. echo "4. Removing Gateway (DELETE)"
  44. curl -s -X DELETE "$BASE_URL/reslevis/removeGateway/$GTW_UUID"
  45. echo -e "\n"
  46. # ---------------------------------------------------------------------------
  47. # ZONES
  48. # ---------------------------------------------------------------------------
  49. echo -e "\n=========================================="
  50. echo "ZONE API TESTS"
  51. echo "=========================================="
  52. echo "5. Creating a test Zone (POST)"
  53. curl -s -X POST "$BASE_URL/reslevis/postZone" \
  54. -H "Content-Type: application/json" \
  55. -d "{\"id\": \"$ZONE_UUID\", \"name\": \"Zone-Smoke-Test\", \"groups\": [\"test\"]}"
  56. echo -e "\n"
  57. echo "6. Listing Zones"
  58. curl -s -X GET "$BASE_URL/reslevis/getZones" | jq '.'
  59. echo -e "\n7. Updating Zone (PUT)"
  60. curl -s -X PUT "$BASE_URL/reslevis/updateZone" \
  61. -H "Content-Type: application/json" \
  62. -d "{\"id\": \"$ZONE_UUID\", \"name\": \"Zone-Smoke-Updated\", \"groups\": [\"test\", \"updated\"]}"
  63. echo -e "\n"
  64. echo "8. Removing Zone (DELETE)"
  65. curl -s -X DELETE "$BASE_URL/reslevis/removeZone/$ZONE_UUID"
  66. echo -e "\n"
  67. # ---------------------------------------------------------------------------
  68. # TRACKERS
  69. # ---------------------------------------------------------------------------
  70. echo -e "\n=========================================="
  71. echo "TRACKER API TESTS"
  72. echo "=========================================="
  73. echo "9. Creating a test Tracker (POST)"
  74. # I valori dei campi battery e temperature sono passati come stringhe ("99", "24")
  75. # per soddisfare la configurazione Go `validate:"required"` e il tag `,string` delle struct.
  76. curl -s -X POST "$BASE_URL/reslevis/postTracker" \
  77. -H "Content-Type: application/json" \
  78. -d "{\"id\": \"$TRK_UUID\", \"name\": \"TRK-SMOKE\", \"mac\": \"00:11:22:33:44:55\", \"status\": \"online\", \"battery\": \"99\", \"temperature\": \"24\"}"
  79. echo -e "\n"
  80. echo "10. Listing Trackers"
  81. curl -s -X GET "$BASE_URL/reslevis/getTrackers" | jq '.'
  82. echo -e "\n11. Updating Tracker (PUT)"
  83. curl -s -X PUT "$BASE_URL/reslevis/updateTracker" \
  84. -H "Content-Type: application/json" \
  85. -d "{\"id\": \"$TRK_UUID\", \"name\": \"TRK-SMOKE-UPDATED\", \"mac\": \"00:11:22:33:44:55\", \"status\": \"offline\", \"battery\": \"80\", \"temperature\": \"22\"}"
  86. echo -e "\n"
  87. echo "12. Removing Tracker (DELETE)"
  88. curl -s -X DELETE "$BASE_URL/reslevis/removeTracker/$TRK_UUID"
  89. echo -e "\n"
  90. # ---------------------------------------------------------------------------
  91. # FLOORS
  92. # ---------------------------------------------------------------------------
  93. echo -e "\n=========================================="
  94. echo "FLOOR API TESTS"
  95. echo "=========================================="
  96. echo "13. Creating a test Floor (POST)"
  97. curl -s -X POST "$BASE_URL/reslevis/postFloor" \
  98. -H "Content-Type: application/json" \
  99. -d "{\"id\": \"$FLR_UUID\", \"name\": \"Floor 1\", \"floornumber\": 1, \"image\": \"\", \"description\": \"Test\", \"scale\": 1, \"building\": \"Main\"}"
  100. echo -e "\n"
  101. echo "14. Listing Floors"
  102. curl -s -X GET "$BASE_URL/reslevis/getFloors" | jq '.'
  103. echo -e "\n15. Removing Floor (DELETE)"
  104. curl -s -X DELETE "$BASE_URL/reslevis/removeFloor/$FLR_UUID"
  105. echo -e "\n"
  106. # ---------------------------------------------------------------------------
  107. # PARSER CONFIGS & SETTINGS
  108. # ---------------------------------------------------------------------------
  109. echo "=========================================="
  110. echo "PARSER CONFIGS & SETTINGS TESTS"
  111. echo "=========================================="
  112. echo "16. Listing Parser Beacons configurations"
  113. curl -s -X GET "$BASE_URL/configs/beacons" | jq '.'
  114. echo -e "\n17. Testing Settings GET"
  115. curl -s -X GET "$BASE_URL/reslevis/settings" | jq '.'
  116. echo -e "\n=========================================="
  117. echo "ALL TESTS COMPLETED"
  118. echo "=========================================="