Makefile 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. # S3 API Retention Test Makefile
  2. # This Makefile provides comprehensive targets for running S3 retention tests
  3. .PHONY: help build-weed setup-server start-server stop-server test-retention test-retention-quick test-retention-comprehensive test-retention-worm test-all clean logs check-deps
  4. # Configuration
  5. WEED_BINARY := ../../../weed/weed_binary
  6. S3_PORT := 8333
  7. MASTER_PORT := 9333
  8. VOLUME_PORT := 8080
  9. FILER_PORT := 8888
  10. TEST_TIMEOUT := 15m
  11. TEST_PATTERN := TestRetention
  12. # Default target
  13. help:
  14. @echo "S3 API Retention Test Makefile"
  15. @echo ""
  16. @echo "Available targets:"
  17. @echo " help - Show this help message"
  18. @echo " build-weed - Build the SeaweedFS binary"
  19. @echo " check-deps - Check dependencies and build binary if needed"
  20. @echo " start-server - Start SeaweedFS server for testing"
  21. @echo " start-server-simple - Start server without process cleanup (for CI)"
  22. @echo " stop-server - Stop SeaweedFS server"
  23. @echo " test-retention - Run all retention tests"
  24. @echo " test-retention-quick - Run core retention tests only"
  25. @echo " test-retention-simple - Run tests without server management"
  26. @echo " test-retention-comprehensive - Run comprehensive retention tests"
  27. @echo " test-retention-worm - Run WORM integration tests"
  28. @echo " test-all - Run all S3 API retention tests"
  29. @echo " test-with-server - Start server, run tests, stop server"
  30. @echo " logs - Show server logs"
  31. @echo " clean - Clean up test artifacts and stop server"
  32. @echo " health-check - Check if server is accessible"
  33. @echo ""
  34. @echo "Configuration:"
  35. @echo " S3_PORT=${S3_PORT}"
  36. @echo " TEST_TIMEOUT=${TEST_TIMEOUT}"
  37. # Build the SeaweedFS binary
  38. build-weed:
  39. @echo "Building SeaweedFS binary..."
  40. @cd ../../../weed && go build -o weed_binary .
  41. @chmod +x $(WEED_BINARY)
  42. @echo "✅ SeaweedFS binary built at $(WEED_BINARY)"
  43. check-deps: build-weed
  44. @echo "Checking dependencies..."
  45. @echo "🔍 DEBUG: Checking Go installation..."
  46. @command -v go >/dev/null 2>&1 || (echo "Go is required but not installed" && exit 1)
  47. @echo "🔍 DEBUG: Go version: $$(go version)"
  48. @echo "🔍 DEBUG: Checking binary at $(WEED_BINARY)..."
  49. @test -f $(WEED_BINARY) || (echo "SeaweedFS binary not found at $(WEED_BINARY)" && exit 1)
  50. @echo "🔍 DEBUG: Binary size: $$(ls -lh $(WEED_BINARY) | awk '{print $$5}')"
  51. @echo "🔍 DEBUG: Binary permissions: $$(ls -la $(WEED_BINARY) | awk '{print $$1}')"
  52. @echo "🔍 DEBUG: Checking Go module dependencies..."
  53. @go list -m github.com/aws/aws-sdk-go-v2 >/dev/null 2>&1 || (echo "AWS SDK Go v2 not found. Run 'go mod tidy'." && exit 1)
  54. @go list -m github.com/stretchr/testify >/dev/null 2>&1 || (echo "Testify not found. Run 'go mod tidy'." && exit 1)
  55. @echo "✅ All dependencies are available"
  56. # Start SeaweedFS server for testing
  57. start-server: check-deps
  58. @echo "Starting SeaweedFS server..."
  59. @echo "🔍 DEBUG: Current working directory: $$(pwd)"
  60. @echo "🔍 DEBUG: Checking for existing weed processes..."
  61. @ps aux | grep weed | grep -v grep || echo "No existing weed processes found"
  62. @echo "🔍 DEBUG: Cleaning up any existing PID file..."
  63. @rm -f weed-server.pid
  64. @echo "🔍 DEBUG: Checking for port conflicts..."
  65. @if netstat -tlnp 2>/dev/null | grep $(S3_PORT) >/dev/null; then \
  66. echo "⚠️ Port $(S3_PORT) is already in use, trying to find the process..."; \
  67. netstat -tlnp 2>/dev/null | grep $(S3_PORT) || true; \
  68. else \
  69. echo "✅ Port $(S3_PORT) is available"; \
  70. fi
  71. @echo "🔍 DEBUG: Checking binary at $(WEED_BINARY)"
  72. @ls -la $(WEED_BINARY) || (echo "❌ Binary not found!" && exit 1)
  73. @echo "🔍 DEBUG: Checking config file at ../../../docker/compose/s3.json"
  74. @ls -la ../../../docker/compose/s3.json || echo "⚠️ Config file not found, continuing without it"
  75. @echo "🔍 DEBUG: Creating volume directory..."
  76. @mkdir -p ./test-volume-data
  77. @echo "🔍 DEBUG: Launching SeaweedFS server in background..."
  78. @echo "🔍 DEBUG: Command: $(WEED_BINARY) server -debug -s3 -s3.port=$(S3_PORT) -s3.allowEmptyFolder=false -s3.allowDeleteBucketNotEmpty=true -s3.config=../../../docker/compose/s3.json -filer -filer.maxMB=64 -master.volumeSizeLimitMB=50 -volume.max=100 -dir=./test-volume-data -volume.preStopSeconds=1 -metricsPort=9324"
  79. @$(WEED_BINARY) server \
  80. -debug \
  81. -s3 \
  82. -s3.port=$(S3_PORT) \
  83. -s3.allowEmptyFolder=false \
  84. -s3.allowDeleteBucketNotEmpty=true \
  85. -s3.config=../../../docker/compose/s3.json \
  86. -filer \
  87. -filer.maxMB=64 \
  88. -master.volumeSizeLimitMB=50 \
  89. -volume.max=100 \
  90. -dir=./test-volume-data \
  91. -volume.preStopSeconds=1 \
  92. -metricsPort=9324 \
  93. > weed-test.log 2>&1 & echo $$! > weed-server.pid
  94. @echo "🔍 DEBUG: Server PID: $$(cat weed-server.pid 2>/dev/null || echo 'PID file not found')"
  95. @echo "🔍 DEBUG: Checking if PID is still running..."
  96. @sleep 2
  97. @if [ -f weed-server.pid ]; then \
  98. SERVER_PID=$$(cat weed-server.pid); \
  99. ps -p $$SERVER_PID || echo "⚠️ Server PID $$SERVER_PID not found after 2 seconds"; \
  100. else \
  101. echo "⚠️ PID file not found"; \
  102. fi
  103. @echo "🔍 DEBUG: Waiting for server to start (up to 90 seconds)..."
  104. @for i in $$(seq 1 90); do \
  105. echo "🔍 DEBUG: Attempt $$i/90 - checking port $(S3_PORT)"; \
  106. if curl -s http://localhost:$(S3_PORT) >/dev/null 2>&1; then \
  107. echo "✅ SeaweedFS server started successfully on port $(S3_PORT) after $$i seconds"; \
  108. exit 0; \
  109. fi; \
  110. if [ $$i -eq 5 ]; then \
  111. echo "🔍 DEBUG: After 5 seconds, checking process and logs..."; \
  112. ps aux | grep weed | grep -v grep || echo "No weed processes found"; \
  113. if [ -f weed-test.log ]; then \
  114. echo "=== First server logs ==="; \
  115. head -20 weed-test.log; \
  116. fi; \
  117. fi; \
  118. if [ $$i -eq 15 ]; then \
  119. echo "🔍 DEBUG: After 15 seconds, checking port bindings..."; \
  120. netstat -tlnp 2>/dev/null | grep $(S3_PORT) || echo "Port $(S3_PORT) not bound"; \
  121. netstat -tlnp 2>/dev/null | grep 9333 || echo "Port 9333 not bound"; \
  122. netstat -tlnp 2>/dev/null | grep 8080 || echo "Port 8080 not bound"; \
  123. fi; \
  124. if [ $$i -eq 30 ]; then \
  125. echo "⚠️ Server taking longer than expected (30s), checking logs..."; \
  126. if [ -f weed-test.log ]; then \
  127. echo "=== Recent server logs ==="; \
  128. tail -20 weed-test.log; \
  129. fi; \
  130. fi; \
  131. sleep 1; \
  132. done; \
  133. echo "❌ Server failed to start within 90 seconds"; \
  134. echo "🔍 DEBUG: Final process check:"; \
  135. ps aux | grep weed | grep -v grep || echo "No weed processes found"; \
  136. echo "🔍 DEBUG: Final port check:"; \
  137. netstat -tlnp 2>/dev/null | grep -E "(8333|9333|8080)" || echo "No ports bound"; \
  138. echo "=== Full server logs ==="; \
  139. if [ -f weed-test.log ]; then \
  140. cat weed-test.log; \
  141. else \
  142. echo "No log file found"; \
  143. fi; \
  144. exit 1
  145. # Stop SeaweedFS server
  146. stop-server:
  147. @echo "Stopping SeaweedFS server..."
  148. @if [ -f weed-server.pid ]; then \
  149. SERVER_PID=$$(cat weed-server.pid); \
  150. echo "Killing server PID $$SERVER_PID"; \
  151. if ps -p $$SERVER_PID >/dev/null 2>&1; then \
  152. kill -TERM $$SERVER_PID 2>/dev/null || true; \
  153. sleep 2; \
  154. if ps -p $$SERVER_PID >/dev/null 2>&1; then \
  155. echo "Process still running, sending KILL signal..."; \
  156. kill -KILL $$SERVER_PID 2>/dev/null || true; \
  157. sleep 1; \
  158. fi; \
  159. else \
  160. echo "Process $$SERVER_PID not found (already stopped)"; \
  161. fi; \
  162. rm -f weed-server.pid; \
  163. else \
  164. echo "No PID file found, checking for running processes..."; \
  165. echo "⚠️ Skipping automatic process cleanup to avoid CI issues"; \
  166. echo "Note: Any remaining weed processes should be cleaned up by the CI environment"; \
  167. fi
  168. @echo "✅ SeaweedFS server stopped"
  169. # Show server logs
  170. logs:
  171. @if test -f weed-test.log; then \
  172. echo "=== SeaweedFS Server Logs ==="; \
  173. tail -f weed-test.log; \
  174. else \
  175. echo "No log file found. Server may not be running."; \
  176. fi
  177. # Core retention tests (basic functionality)
  178. test-retention-quick: check-deps
  179. @echo "Running core S3 retention tests..."
  180. @go test -v -timeout=$(TEST_TIMEOUT) -run "TestBasicRetentionWorkflow|TestRetentionModeCompliance|TestLegalHoldWorkflow" .
  181. @echo "✅ Core retention tests completed"
  182. # All retention tests (comprehensive)
  183. test-retention: check-deps
  184. @echo "Running all S3 retention tests..."
  185. @go test -v -timeout=$(TEST_TIMEOUT) -run "$(TEST_PATTERN)" .
  186. @echo "✅ All retention tests completed"
  187. # WORM integration tests
  188. test-retention-worm: check-deps
  189. @echo "Running WORM integration tests..."
  190. @go test -v -timeout=$(TEST_TIMEOUT) -run "TestWORM|TestRetentionExtendedAttributes|TestRetentionConcurrentOperations" .
  191. @echo "✅ WORM integration tests completed"
  192. # Comprehensive retention tests (all features)
  193. test-retention-comprehensive: check-deps
  194. @echo "Running comprehensive S3 retention tests..."
  195. @go test -v -timeout=$(TEST_TIMEOUT) -run "TestRetention|TestObjectLock|TestLegalHold|TestWORM" .
  196. @echo "✅ Comprehensive retention tests completed"
  197. # All tests without server management
  198. test-retention-simple: check-deps
  199. @echo "Running retention tests (assuming server is already running)..."
  200. @go test -v -timeout=$(TEST_TIMEOUT) .
  201. @echo "✅ All retention tests completed"
  202. # Start server, run tests, stop server
  203. test-with-server: start-server
  204. @echo "Running retention tests with managed server..."
  205. @sleep 5 # Give server time to fully start
  206. @make test-retention-comprehensive || (echo "Tests failed, stopping server..." && make stop-server && exit 1)
  207. @make stop-server
  208. @echo "✅ All tests completed with managed server"
  209. # Health check
  210. health-check:
  211. @echo "Checking server health..."
  212. @if curl -s http://localhost:$(S3_PORT) >/dev/null 2>&1; then \
  213. echo "✅ Server is accessible on port $(S3_PORT)"; \
  214. else \
  215. echo "❌ Server is not accessible on port $(S3_PORT)"; \
  216. exit 1; \
  217. fi
  218. # Clean up
  219. clean:
  220. @echo "Cleaning up test artifacts..."
  221. @make stop-server
  222. @rm -f weed-test.log
  223. @rm -f weed-server.pid
  224. @rm -rf ./test-volume-data
  225. @echo "✅ Cleanup completed"
  226. # Individual test targets for specific functionality
  227. test-basic-retention:
  228. @echo "Running basic retention tests..."
  229. @go test -v -timeout=$(TEST_TIMEOUT) -run "TestBasicRetentionWorkflow" .
  230. test-compliance-retention:
  231. @echo "Running compliance retention tests..."
  232. @go test -v -timeout=$(TEST_TIMEOUT) -run "TestRetentionModeCompliance" .
  233. test-legal-hold:
  234. @echo "Running legal hold tests..."
  235. @go test -v -timeout=$(TEST_TIMEOUT) -run "TestLegalHoldWorkflow" .
  236. test-object-lock-config:
  237. @echo "Running object lock configuration tests..."
  238. @go test -v -timeout=$(TEST_TIMEOUT) -run "TestObjectLockConfiguration" .
  239. test-retention-versions:
  240. @echo "Running retention with versions tests..."
  241. @go test -v -timeout=$(TEST_TIMEOUT) -run "TestRetentionWithVersions" .
  242. test-retention-combination:
  243. @echo "Running retention and legal hold combination tests..."
  244. @go test -v -timeout=$(TEST_TIMEOUT) -run "TestRetentionAndLegalHoldCombination" .
  245. test-expired-retention:
  246. @echo "Running expired retention tests..."
  247. @go test -v -timeout=$(TEST_TIMEOUT) -run "TestExpiredRetention" .
  248. test-retention-errors:
  249. @echo "Running retention error case tests..."
  250. @go test -v -timeout=$(TEST_TIMEOUT) -run "TestRetentionErrorCases" .
  251. # WORM-specific test targets
  252. test-worm-integration:
  253. @echo "Running WORM integration tests..."
  254. @go test -v -timeout=$(TEST_TIMEOUT) -run "TestWORMRetentionIntegration" .
  255. test-worm-legacy:
  256. @echo "Running WORM legacy compatibility tests..."
  257. @go test -v -timeout=$(TEST_TIMEOUT) -run "TestWORMLegacyCompatibility" .
  258. test-retention-overwrite:
  259. @echo "Running retention overwrite protection tests..."
  260. @go test -v -timeout=$(TEST_TIMEOUT) -run "TestRetentionOverwriteProtection" .
  261. test-retention-bulk:
  262. @echo "Running retention bulk operations tests..."
  263. @go test -v -timeout=$(TEST_TIMEOUT) -run "TestRetentionBulkOperations" .
  264. test-retention-multipart:
  265. @echo "Running retention multipart upload tests..."
  266. @go test -v -timeout=$(TEST_TIMEOUT) -run "TestRetentionWithMultipartUpload" .
  267. test-retention-extended-attrs:
  268. @echo "Running retention extended attributes tests..."
  269. @go test -v -timeout=$(TEST_TIMEOUT) -run "TestRetentionExtendedAttributes" .
  270. test-retention-defaults:
  271. @echo "Running retention bucket defaults tests..."
  272. @go test -v -timeout=$(TEST_TIMEOUT) -run "TestRetentionBucketDefaults" .
  273. test-retention-concurrent:
  274. @echo "Running retention concurrent operations tests..."
  275. @go test -v -timeout=$(TEST_TIMEOUT) -run "TestRetentionConcurrentOperations" .
  276. # Development targets
  277. dev-start: start-server
  278. @echo "Development server started. Access S3 API at http://localhost:$(S3_PORT)"
  279. @echo "To stop: make stop-server"
  280. dev-test: check-deps
  281. @echo "Running tests in development mode..."
  282. @go test -v -timeout=$(TEST_TIMEOUT) -run "TestBasicRetentionWorkflow" .
  283. # CI targets
  284. ci-test: check-deps
  285. @echo "Running tests in CI mode..."
  286. @go test -v -timeout=$(TEST_TIMEOUT) -race .
  287. # All targets
  288. test-all: test-retention test-retention-worm
  289. @echo "✅ All S3 retention tests completed"
  290. # Benchmark targets
  291. benchmark-retention:
  292. @echo "Running retention performance benchmarks..."
  293. @go test -v -timeout=$(TEST_TIMEOUT) -bench=. -benchmem .
  294. # Coverage targets
  295. coverage:
  296. @echo "Running tests with coverage..."
  297. @go test -v -timeout=$(TEST_TIMEOUT) -coverprofile=coverage.out .
  298. @go tool cover -html=coverage.out -o coverage.html
  299. @echo "Coverage report generated: coverage.html"
  300. # Format and lint
  301. fmt:
  302. @echo "Formatting Go code..."
  303. @go fmt .
  304. lint:
  305. @echo "Running linter..."
  306. @golint . || echo "golint not available, skipping..."
  307. # Install dependencies for development
  308. install-deps:
  309. @echo "Installing Go dependencies..."
  310. @go mod tidy
  311. @go mod download
  312. # Show current configuration
  313. show-config:
  314. @echo "Current configuration:"
  315. @echo " WEED_BINARY: $(WEED_BINARY)"
  316. @echo " S3_PORT: $(S3_PORT)"
  317. @echo " TEST_TIMEOUT: $(TEST_TIMEOUT)"
  318. @echo " TEST_PATTERN: $(TEST_PATTERN)"