Skip to content

Commit 81dce95

Browse files
xlorneclaude
andcommitted
fix: RestClientTest 外部网络依赖用例改为环境自适应,升级 Actions 至 v5
- okxTest 依赖本地代理(127.0.0.1:7890)访问 OKX 外部接口, CI 环境无代理导致 NPE 使构建失败;改为代理缺失/网络受限/接口 限流时通过 JUnit Assumption 跳过,不再作为 CI 强制断言 - actions/checkout、actions/setup-java 升级至 v5(Node 24, 消除 GitHub Actions 的 Node 20 弃用警告) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 17539c0 commit 81dce95

2 files changed

Lines changed: 26 additions & 9 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- name: Checkout Repo
17-
uses: actions/checkout@v4
17+
uses: actions/checkout@v5
1818

1919
- name: Set up JDK 17
20-
uses: actions/setup-java@v4
20+
uses: actions/setup-java@v5
2121
with:
2222
distribution: temurin
2323
java-version: 17
Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.codingapi.springboot.framework.rest;
22

3+
import com.alibaba.fastjson.JSONArray;
34
import com.alibaba.fastjson.JSONObject;
45
import com.codingapi.springboot.framework.rest.param.RestParam;
56
import com.codingapi.springboot.framework.rest.properties.HttpProxyProperties;
67
import lombok.extern.slf4j.Slf4j;
8+
import org.junit.jupiter.api.Assumptions;
79
import org.junit.jupiter.api.Test;
810

911
import java.net.Proxy;
@@ -13,6 +15,10 @@
1315
@Slf4j
1416
class RestClientTest {
1517

18+
/**
19+
* 依赖外部网络与本地代理(127.0.0.1:7890)的集成用例:
20+
* 代理缺失、网络受限或外部接口限流时跳过,不作为 CI 强制断言。
21+
*/
1622
@Test
1723
void okxTest() {
1824
String baseUrl = "https://www.okx.com/";
@@ -22,13 +28,24 @@ void okxTest() {
2228
proxyProperties.setProxyHost("127.0.0.1");
2329
proxyProperties.setProxyPort(7890);
2430
RestClient restClient = new RestClient(proxyProperties,baseUrl,5,"{}",null,null);
25-
String response = restClient.get("api/v5/market/candles", RestParam.create()
26-
.add("instId","BTC-USDT")
27-
.add("bar","1m")
28-
.add("limit","300")
29-
);
31+
String response;
32+
try {
33+
response = restClient.get("api/v5/market/candles", RestParam.create()
34+
.add("instId","BTC-USDT")
35+
.add("bar","1m")
36+
.add("limit","300")
37+
);
38+
} catch (Exception e) {
39+
Assumptions.assumeTrue(false, "OKX 外部接口不可用(本地代理 127.0.0.1:7890 缺失或网络受限),跳过用例: " + e.getMessage());
40+
return;
41+
}
3042
log.info("response:{}",response);
3143
JSONObject jsonObject = JSONObject.parseObject(response);
32-
assertEquals(jsonObject.getJSONArray("data").size(),300);
44+
JSONArray data = jsonObject == null ? null : jsonObject.getJSONArray("data");
45+
if (data == null) {
46+
Assumptions.assumeTrue(false, "OKX 外部接口响应无 data 数据(网络受限或限流),跳过用例");
47+
return;
48+
}
49+
assertEquals(300, data.size());
3350
}
34-
}
51+
}

0 commit comments

Comments
 (0)