validator_integration_test.sh 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. #!/bin/bash
  2. # Integration test for content_validator
  3. set -e
  4. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  5. REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
  6. BUILD_DIR="${BUILD_DIR:-$REPO_ROOT/build}"
  7. VALIDATOR="$BUILD_DIR/bin/content_validator"
  8. # Colors for output
  9. RED='\033[0;31m'
  10. GREEN='\033[0;32m'
  11. YELLOW='\033[1;33m'
  12. NC='\033[0m' # No Color
  13. echo "Content Validator Integration Tests"
  14. echo "===================================="
  15. echo ""
  16. # Check if validator exists
  17. if [ ! -x "$VALIDATOR" ]; then
  18. echo -e "${RED}✗ Validator not found at: $VALIDATOR${NC}"
  19. echo "Please build the project first with: make build"
  20. exit 1
  21. fi
  22. echo -e "${GREEN}✓ Validator found${NC}"
  23. echo ""
  24. # Test 1: Valid assets directory
  25. echo "Test 1: Validating assets directory..."
  26. if "$VALIDATOR" "$REPO_ROOT/assets"; then
  27. echo -e "${GREEN}✓ Test 1 passed: Assets validated successfully${NC}"
  28. else
  29. echo -e "${RED}✗ Test 1 failed: Asset validation failed${NC}"
  30. exit 1
  31. fi
  32. echo ""
  33. # Test 2: Invalid directory (should fail gracefully)
  34. echo "Test 2: Testing with invalid directory..."
  35. if "$VALIDATOR" "/nonexistent/directory" 2>/dev/null; then
  36. echo -e "${RED}✗ Test 2 failed: Should have failed with invalid directory${NC}"
  37. exit 1
  38. else
  39. echo -e "${GREEN}✓ Test 2 passed: Correctly failed with invalid directory${NC}"
  40. fi
  41. echo ""
  42. # Test 3: Create temporary test missions and campaigns
  43. echo "Test 3: Testing with custom test data..."
  44. TEMP_DIR=$(mktemp -d)
  45. mkdir -p "$TEMP_DIR/missions"
  46. mkdir -p "$TEMP_DIR/campaigns"
  47. # Create a valid test mission
  48. cat > "$TEMP_DIR/missions/test_mission.json" << 'EOF'
  49. {
  50. "id": "test_mission",
  51. "title": "Test Mission",
  52. "summary": "A test mission",
  53. "map_path": ":/assets/maps/map_forest.json",
  54. "player_setup": {
  55. "nation": "roman_republic",
  56. "faction": "roman",
  57. "color": "red",
  58. "starting_units": [],
  59. "starting_buildings": [],
  60. "starting_resources": {"gold": 0, "food": 0}
  61. },
  62. "ai_setups": [],
  63. "victory_conditions": [
  64. {"type": "destroy_all_enemies", "description": "Win"}
  65. ],
  66. "defeat_conditions": [],
  67. "events": []
  68. }
  69. EOF
  70. # Create a valid test campaign
  71. cat > "$TEMP_DIR/campaigns/test_campaign.json" << 'EOF'
  72. {
  73. "id": "test_campaign",
  74. "title": "Test Campaign",
  75. "description": "A test campaign",
  76. "missions": [
  77. {
  78. "mission_id": "test_mission",
  79. "order_index": 0
  80. }
  81. ]
  82. }
  83. EOF
  84. if "$VALIDATOR" "$TEMP_DIR"; then
  85. echo -e "${GREEN}✓ Test 3 passed: Custom test data validated${NC}"
  86. else
  87. echo -e "${RED}✗ Test 3 failed: Custom test data validation failed${NC}"
  88. rm -rf "$TEMP_DIR"
  89. exit 1
  90. fi
  91. rm -rf "$TEMP_DIR"
  92. echo ""
  93. # Test 4: Invalid JSON (should fail)
  94. echo "Test 4: Testing with invalid JSON..."
  95. TEMP_DIR=$(mktemp -d)
  96. mkdir -p "$TEMP_DIR/missions"
  97. cat > "$TEMP_DIR/missions/invalid.json" << 'EOF'
  98. {
  99. "id": "invalid"
  100. "missing": "comma"
  101. }
  102. EOF
  103. if "$VALIDATOR" "$TEMP_DIR" 2>/dev/null; then
  104. echo -e "${RED}✗ Test 4 failed: Should have failed with invalid JSON${NC}"
  105. rm -rf "$TEMP_DIR"
  106. exit 1
  107. else
  108. echo -e "${GREEN}✓ Test 4 passed: Correctly failed with invalid JSON${NC}"
  109. fi
  110. rm -rf "$TEMP_DIR"
  111. echo ""
  112. # Test 5: Missing required fields
  113. echo "Test 5: Testing with missing required fields..."
  114. TEMP_DIR=$(mktemp -d)
  115. mkdir -p "$TEMP_DIR/missions"
  116. cat > "$TEMP_DIR/missions/incomplete.json" << 'EOF'
  117. {
  118. "title": "Incomplete Mission"
  119. }
  120. EOF
  121. if "$VALIDATOR" "$TEMP_DIR" 2>/dev/null; then
  122. echo -e "${RED}✗ Test 5 failed: Should have failed with missing fields${NC}"
  123. rm -rf "$TEMP_DIR"
  124. exit 1
  125. else
  126. echo -e "${GREEN}✓ Test 5 passed: Correctly failed with missing fields${NC}"
  127. fi
  128. rm -rf "$TEMP_DIR"
  129. echo ""
  130. # Test 6: Campaign with non-contiguous order indices
  131. echo "Test 6: Testing campaign with non-contiguous order indices..."
  132. TEMP_DIR=$(mktemp -d)
  133. mkdir -p "$TEMP_DIR/missions"
  134. mkdir -p "$TEMP_DIR/campaigns"
  135. # Create missions
  136. cat > "$TEMP_DIR/missions/mission1.json" << 'EOF'
  137. {
  138. "id": "mission1",
  139. "title": "Mission 1",
  140. "summary": "First mission",
  141. "map_path": ":/assets/maps/map_forest.json",
  142. "player_setup": {"nation": "roman_republic", "faction": "roman", "color": "red", "starting_units": [], "starting_buildings": [], "starting_resources": {"gold": 0, "food": 0}},
  143. "ai_setups": [],
  144. "victory_conditions": [{"type": "destroy_all_enemies", "description": "Win"}],
  145. "defeat_conditions": [],
  146. "events": []
  147. }
  148. EOF
  149. cat > "$TEMP_DIR/missions/mission2.json" << 'EOF'
  150. {
  151. "id": "mission2",
  152. "title": "Mission 2",
  153. "summary": "Second mission",
  154. "map_path": ":/assets/maps/map_forest.json",
  155. "player_setup": {"nation": "roman_republic", "faction": "roman", "color": "red", "starting_units": [], "starting_buildings": [], "starting_resources": {"gold": 0, "food": 0}},
  156. "ai_setups": [],
  157. "victory_conditions": [{"type": "destroy_all_enemies", "description": "Win"}],
  158. "defeat_conditions": [],
  159. "events": []
  160. }
  161. EOF
  162. # Campaign with gaps in order_index (0, 2 - missing 1)
  163. cat > "$TEMP_DIR/campaigns/bad_campaign.json" << 'EOF'
  164. {
  165. "id": "bad_campaign",
  166. "title": "Bad Campaign",
  167. "description": "Campaign with order gaps",
  168. "missions": [
  169. {"mission_id": "mission1", "order_index": 0},
  170. {"mission_id": "mission2", "order_index": 2}
  171. ]
  172. }
  173. EOF
  174. if "$VALIDATOR" "$TEMP_DIR" 2>/dev/null; then
  175. echo -e "${RED}✗ Test 6 failed: Should have failed with non-contiguous indices${NC}"
  176. rm -rf "$TEMP_DIR"
  177. exit 1
  178. else
  179. echo -e "${GREEN}✓ Test 6 passed: Correctly failed with non-contiguous indices${NC}"
  180. fi
  181. rm -rf "$TEMP_DIR"
  182. echo ""
  183. echo "===================================="
  184. echo -e "${GREEN}All tests passed!${NC}"
  185. echo ""