|
| 1 | +--- |
| 2 | +title: Integration Test |
| 3 | +type: docs |
| 4 | +description: |
| 5 | +author: HUATUO Team |
| 6 | +date: 2026-03-04 |
| 7 | +weight: 4 |
| 8 | +--- |
| 9 | + |
| 10 | +This integration test validates that **huatuo-bamai** can start correctly with mocked `/proc` and `/sys` filesystems and expose the expected **Prometheus metrics**. |
| 11 | + |
| 12 | +The test runs the real `huatuo-bamai` binary and verifies the `/metrics`endpoint output without relying on the host kernel or hardware. |
| 13 | + |
| 14 | +## What the Script Does |
| 15 | +The integration test performs the following steps: |
| 16 | + |
| 17 | +1. Generates a temporary `bamai.conf` |
| 18 | +2. Starts `huatuo-bamai` with mocked `procfs` and `sysfs` |
| 19 | +3. Waits for the Prometheus `/metrics` endpoint to become available |
| 20 | +4. Fetches all metrics from `/metrics` |
| 21 | +5. Verifies that all expected metrics exist |
| 22 | +6. Stops the service and cleans up resources |
| 23 | + |
| 24 | +If any expected metric is missing, the test fails. |
| 25 | + |
| 26 | +## How to Run |
| 27 | +Run the integration test from the project root: |
| 28 | + |
| 29 | +```bash |
| 30 | +bash integration/integration.sh |
| 31 | +``` |
| 32 | +or |
| 33 | +```bash |
| 34 | +make integration |
| 35 | +``` |
| 36 | +### On Failure |
| 37 | + |
| 38 | +- The `huatuo-bamai` service metrics and logs are printed to stdout |
| 39 | +- The temporary working directory is kept for debugging |
| 40 | + |
| 41 | +### On Success |
| 42 | + |
| 43 | +- Output the list of successfully validated metrics |
| 44 | + |
| 45 | +--- |
| 46 | + |
| 47 | +## How to Add New Metrics Tests |
| 48 | +### Step 1: Add or Update Fixture Data |
| 49 | + |
| 50 | +If the metric depends on /proc or /sys, add or update mock data under: |
| 51 | +```bash |
| 52 | +integration/fixtures/ |
| 53 | +``` |
| 54 | + |
| 55 | +The directory structure should match the real kernel filesystem layout. |
| 56 | +### Step 2: Add Expected Metrics |
| 57 | + |
| 58 | +Create a new file under: |
| 59 | +```bash |
| 60 | +integration/fixtures/expected_metrics/ |
| 61 | +├── cpu.txt |
| 62 | +├── memory.txt |
| 63 | +└── ... |
| 64 | +``` |
| 65 | + |
| 66 | +Each non-empty, non-comment line represents one expected Prometheus metric line |
| 67 | +and must match the /metrics output exactly. |
| 68 | + |
| 69 | +New *.txt files are automatically picked up by the test. |
| 70 | + |
| 71 | +### Step 3: Run the Test |
| 72 | +```bash |
| 73 | +bash integration/integration.sh |
| 74 | +``` |
| 75 | +The test fails if any expected metric is missing or mismatched. |
0 commit comments