Skip to content

Commit 211bf30

Browse files
liuchangyanhao022
authored andcommitted
docs: add integration tests description
Signed-off-by: Teresaliu <teresaliu@didiglobal.com>
1 parent 8afb224 commit 211bf30

10 files changed

Lines changed: 150 additions & 8 deletions

File tree

docs/best-practice/_index_en.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ type: docs
44
description:
55
author: HUATUO Team
66
date: 2026-01-11
7-
weight: 5
7+
weight: 6
88
---

docs/best-practice/_index_zh.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ type: docs
44
description:
55
author: HUATUO Team
66
date: 2026-01-11
7-
weight: 5
7+
weight: 6
88
---

docs/development/_index_en.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ type: docs
44
description:
55
author: HUATUO Team
66
date: 2026-01-11
7-
weight: 6
7+
weight: 7
88
---

docs/development/_index_zh.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ type: docs
44
description:
55
author: HUATUO Team
66
date: 2026-01-11
7-
weight: 6
7+
weight: 7
88
---

docs/faq/_index_en.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
title: Frequenty Asked Questions
33
type: docs
4-
weight: 7
4+
weight: 8
55
---

docs/faq/_index_zh.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
title: 常见问题
33
type: docs
4-
weight: 7
4+
weight: 8
55
---

docs/integration_en.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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.

docs/integration_zh.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
title: 集成测试
3+
type: docs
4+
description:
5+
author: HUATUO Team
6+
date: 2026-03-04
7+
weight: 4
8+
---
9+
10+
集成测试用于验证 ``huatuo-bamai``在使用模拟的 ``/proc````/sys`` 文件系统时,能够正确启动并对外暴露符合预期的``Prometheus``指标。
11+
12+
测试运行的是真实的可执行文件,并通过校验 ``/metrics`` 接口的输出结果,确保指标采集与暴露逻辑正确,而不依赖宿主机的内核或硬件环境。
13+
14+
## 脚本执行流程
15+
16+
该集成测试脚本主要包含以下步骤:
17+
18+
1. 生成临时的``bamai.conf``配置文件
19+
2. 使用模拟的 ``procfs````sysfs`` 启动 ``huatuo-bamai`` 服务
20+
3. 等待 ``/metrics`` 接口可访问
21+
4.``/metrics`` 接口拉取所有指标数据
22+
5. 校验所有预期指标是否存在且内容匹配
23+
6. 停止服务并清理相关资源
24+
7. 若任意一个预期指标缺失或不匹配,测试将直接失败
25+
26+
## 运行方式
27+
28+
请在项目根目录下执行集成测试:
29+
```bash
30+
bash integration/integration.sh
31+
```
32+
或通过 Makefile 执行:
33+
```bash
34+
make integration
35+
```
36+
37+
### 失败时的行为
38+
- ``huatuo-bamai`` 服务指标和日志将直接输出到标准输出,便于问题定位
39+
- 临时工作目录将被保留,用于后续调试分析
40+
41+
### 成功时的行为
42+
- 显示验证成功的``metrics`` 列表
43+
---
44+
45+
## 如何新增指标测试
46+
### 第一步:新增或更新模拟数据
47+
如果新增的指标依赖 ``/proc````/sys`` 文件内容,请在以下目录中新增或修改模拟数据:
48+
```bash
49+
integration/fixtures/
50+
```
51+
目录结构需与真实内核文件系统保持一致。
52+
53+
### 第二步:添加预期指标
54+
在以下目录中新建一个文件:
55+
```bash
56+
integration/fixtures/expected_metrics/
57+
├── cpu.txt
58+
├── memory.txt
59+
└── ...
60+
```
61+
每一行(非空、非注释行)表示一条期望的 Prometheus 指标,指标内容必须与 ``/metrics`` 接口返回结果完全一致,新增的``*.txt`` 文件会被测试脚本自动加载并参与校验。
62+
63+
### 第三步:运行测试
64+
```bash
65+
bash integration/integration.sh
66+
```
67+
当任意一个预期指标缺失或不匹配时,测试将失败。

docs/key-feature/_index_en.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ type: docs
44
description:
55
author: HUATUO Team
66
date: 2026-01-11
7-
weight: 4
7+
weight: 5
88
---

docs/key-feature/_index_zh.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ type: docs
44
description:
55
author: HUATUO Team
66
date: 2026-01-11
7-
weight: 4
7+
weight: 5
88
---

0 commit comments

Comments
 (0)