Skip to content

Add Docker-based integration test suite#11

Closed
Copilot wants to merge 4 commits intomainfrom
copilot/create-integration-tests-snipe-it
Closed

Add Docker-based integration test suite#11
Copilot wants to merge 4 commits intomainfrom
copilot/create-integration-tests-snipe-it

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 31, 2026

  • Explore repo structure and understand existing tests and module
  • Create Tests/Integration/docker-compose.yml — Snipe-IT + MySQL stack for testing
  • Create Tests/Integration/setup.php — PHP bootstrap script to create admin user with API token
  • Create Tests/Integration/Start-TestEnvironment.ps1 — start Docker, wait for health, provision admin, return {Url, Token}
  • Create Tests/Integration/Stop-TestEnvironment.ps1 — tear-down Docker stack with --volumes --remove-orphans
  • Create Tests/Integration/SnipeIT.Integration.Tests.ps1 — 52-test Pester file covering CRUD + checkout/checkin
  • Create .github/workflows/integration.yml — GitHub Actions workflow for integration tests
  • Fix unit CI failures: changed path from ./Tests to ./Tests/Unit; improved docker-compose.yml snipeit healthcheck to check API returns 401
  • Fix integration test timeout:
    • docker-compose.yml: changed MySQL healthcheck from -h localhost (Unix socket) to -h 127.0.0.1 -P 3306 (TCP) — ensures MySQL is accepting TCP connections (not just socket) before Snipe-IT starts, preventing Connection refused during migrations
    • integration.yml: replaced docker-health-status poll with a direct HTTP poll for Apache (http://localhost:8000/), followed by an explicit php artisan migrate --force step (idempotent — fixes startup if migration failed), then a second poll for the API returning 401

Copilot AI changed the title [WIP] Add integration tests for Snipe-IT instance using Docker Add Docker-based integration test suite Mar 31, 2026
Copilot AI requested a review from djeborn March 31, 2026 20:15
@djeborn
Copy link
Copy Markdown
Owner

djeborn commented Mar 31, 2026

@copilot - Can you go fix the errors there?

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 31, 2026

@copilot - Can you go fix the errors there?

Fixed in commit 2fc8ad6. Two issues were causing CI failures:

  1. CI workflow picked up integration tests$config.Run.Path was set to ./Tests which includes Tests/Integration/. On Ubuntu runners Docker is available, so the integration tests tried to start the stack. On Windows they crashed the test container entirely. Fixed by changing the path to ./Tests/Unit.

  2. Docker healthcheck passed too early — the original check (curl -sf http://localhost/) passed as soon as Apache started, before DB migrations finished. The provision step would then run setup.php against a DB with no tables, producing the Table 'snipeit.users' doesn't exist errors. Fixed by checking that the /api/v1/hardware API endpoint returns 401 (Unauthenticated), which only happens once Laravel migrations have completed and the app is fully ready.

@djeborn
Copy link
Copy Markdown
Owner

djeborn commented Mar 31, 2026

@copilot - Fix the integration test error.

…icit migration step

Agent-Logs-Url: https://github.com/djeborn/snipe-it-ps/sessions/a4af0c6d-e434-4dd0-bcbc-ceb039f4044b

Co-authored-by: djeborn <116414068+djeborn@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 31, 2026

@copilot - Fix the integration test error.

Fixed in commit a12b89b. Two root causes:

  1. MySQL healthcheck used Unix socket, not TCP — the check used -h localhost which verifies the socket inside the mysql container, but Snipe-IT connects via TCP to mysql:3306. The socket can be ready before TCP, so Snipe-IT got Connection refused during migrations. Fixed by changing to -h 127.0.0.1 -P 3306 (explicit TCP).

  2. Migrations only ran once at startup and were never retried — when migrations failed, Apache started anyway with an empty DB. The health check waited for the API to return 401, but with no tables it would never 401, causing a 6-minute timeout. Fixed the workflow with three distinct steps:

    • Wait for Apache to respond on port 8000 (HTTP poll, no longer relying on docker health state)
    • Explicitly run php artisan migrate --force (idempotent — no-op if migrations already ran, fix if they failed)
    • Wait for /api/v1/hardware to return 401 before provisioning

@djeborn djeborn closed this Mar 31, 2026
@djeborn djeborn deleted the copilot/create-integration-tests-snipe-it branch March 31, 2026 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants