Skip to content

test: 修复测试依赖本地网络环境和权限问题 - #24

Merged
XuHenghenglumia merged 2 commits into
LinuxHub-Group:masterfrom
XuHenghenglumia:fix/tests
Jul 31, 2026
Merged

test: 修复测试依赖本地网络环境和权限问题#24
XuHenghenglumia merged 2 commits into
LinuxHub-Group:masterfrom
XuHenghenglumia:fix/tests

Conversation

@XuHenghenglumia

Copy link
Copy Markdown
Member

改动内容

修复 pkg/lmap/ping_test.go 的 3 个问题(详见 #23):

  1. TestPing 硬编码了局域网 IP 192.168.0.106 → 改为公网稳定地址 1.1.1.1,不再依赖本地网络环境
  2. TestPingWithInvalidIP 使用 0.0.0.0 → 改为 IANA 保留的 TEST-NET-1 地址 192.0.2.1(该地址永不响应,测试结果稳定)
  3. ICMP 需要 root 权限导致 CI 测试一直失败 → CI test 步骤加 sudo
  4. Makefile 的 -tags integration 没有对应 build tag → 删除无效标签

验证

  • gofmt -s -d 通过
  • go build 通过
  • go vet 通过

说明

本地非 root 用户跑 ICMP 测试仍会报 operation not permitted,这是系统权限限制,CI 加 sudo 后即可正常执行。

Fixes #23

- TestPing 改用公网稳定地址 1.1.1.1,不再硬编码局域网 IP
- TestPingWithInvalidIP 改用 IANA 保留地址 192.0.2.1
- CI test 步骤加 sudo(ICMP 需要 root 权限)
- Makefile 去掉无效的 -tags integration
GitHub Actions 禁止出站 ICMP,公网地址在 CI 中永远不可达。
回环地址不依赖出站网络,与 TestPingWithLocalhost 合并。
@XuHenghenglumia
XuHenghenglumia merged commit 0f50ab1 into LinuxHub-Group:master Jul 31, 2026
1 check passed
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.

修复测试:硬编码 IP 导致测试和 CI 无法通过

1 participant