This is an automated email from the ASF dual-hosted git repository.
jinrongtong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git
The following commit(s) were added to refs/heads/master by this push:
new ce8306a [ISSUE #359] Fix fail test in LoginControllerTest and add
.env (#363)
ce8306a is described below
commit ce8306a602f6fa334495f9999084d01cc5284726
Author: Crazylychee <[email protected]>
AuthorDate: Sat Aug 30 19:25:05 2025 +0800
[ISSUE #359] Fix fail test in LoginControllerTest and add .env (#363)
* commit
* commit
* commit
* commit
---
frontend-new/.env.development | 1 +
frontend-new/.env.production | 1 +
frontend-new/src/api/remoteApi/remoteApi.js | 13 +++++--------
src/main/docker/Dockerfile | 2 +-
.../rocketmq/dashboard/controller/LoginControllerTest.java | 12 +++++-------
5 files changed, 13 insertions(+), 16 deletions(-)
diff --git a/frontend-new/.env.development b/frontend-new/.env.development
new file mode 100644
index 0000000..4e8e19e
--- /dev/null
+++ b/frontend-new/.env.development
@@ -0,0 +1 @@
+REACT_APP_API_BASE_URL=http://localhost:8082
diff --git a/frontend-new/.env.production b/frontend-new/.env.production
new file mode 100644
index 0000000..d8038ca
--- /dev/null
+++ b/frontend-new/.env.production
@@ -0,0 +1 @@
+REACT_APP_API_BASE_URL=
diff --git a/frontend-new/src/api/remoteApi/remoteApi.js
b/frontend-new/src/api/remoteApi/remoteApi.js
index c727f55..e39a9c6 100644
--- a/frontend-new/src/api/remoteApi/remoteApi.js
+++ b/frontend-new/src/api/remoteApi/remoteApi.js
@@ -16,7 +16,7 @@
*/
const appConfig = {
- apiBaseUrl: 'http://localhost:8082'
+ apiBaseUrl: process.env.REACT_APP_API_BASE_URL || window.location.origin
};
let _redirectHandler = null;
@@ -954,21 +954,18 @@ const remoteApi = {
};
const tools = {
- // 适配新的数据结构
dashboardRefreshTime: 5000,
generateBrokerMap: (brokerServer, clusterAddrTable, brokerAddrTable) => {
- const clusterMap = {}; // 最终存储 { clusterName: [brokerInstance1,
brokerInstance2, ...] }
+ const clusterMap = {};
Object.entries(clusterAddrTable).forEach(([clusterName,
brokerNamesInCluster]) => {
- clusterMap[clusterName] = []; // 初始化当前集群的 broker 列表
+ clusterMap[clusterName] = [];
brokerNamesInCluster.forEach(brokerName => {
- // 从 brokerAddrTable 获取当前 brokerName 下的所有 brokerId 及其地址
- const brokerAddrs = brokerAddrTable[brokerName]?.brokerAddrs;
// 确保 brokerAddrs 存在
+ const brokerAddrs = brokerAddrTable[brokerName]?.brokerAddrs;
if (brokerAddrs) {
Object.entries(brokerAddrs).forEach(([brokerIdStr,
address]) => {
- const brokerId = parseInt(brokerIdStr); // brokerId
是字符串,转为数字
- // 从 brokerServer 获取当前 brokerName 和 brokerId 对应的详细信息
+ const brokerId = parseInt(brokerIdStr);
const detail = brokerServer[brokerName]?.[brokerIdStr];
if (detail) {
diff --git a/src/main/docker/Dockerfile b/src/main/docker/Dockerfile
index 391fd7d..2961fed 100644
--- a/src/main/docker/Dockerfile
+++ b/src/main/docker/Dockerfile
@@ -15,7 +15,7 @@
# limitations under the License.
#
-FROM java:8
+FROM eclipse-temurin:17.0.16_8-jre-ubi9-minimal
VOLUME /tmp
ADD rocketmq-dashboard-*.jar rocketmq-dashboard.jar
RUN sh -c 'touch /rocketmq-dashboard.jar'
diff --git
a/src/test/java/org/apache/rocketmq/dashboard/controller/LoginControllerTest.java
b/src/test/java/org/apache/rocketmq/dashboard/controller/LoginControllerTest.java
index 95aa8e3..dcfb668 100644
---
a/src/test/java/org/apache/rocketmq/dashboard/controller/LoginControllerTest.java
+++
b/src/test/java/org/apache/rocketmq/dashboard/controller/LoginControllerTest.java
@@ -28,6 +28,7 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.util.ReflectionUtils;
@@ -87,15 +88,14 @@ public class LoginControllerTest extends BaseControllerTest
{
final String rightPwd = "admin";
final String wrongPwd = "rocketmq";
- // 模拟 userService.queryByName 方法返回一个用户
User user = new User("admin", "admin", 1);
user.setPassword(rightPwd);
// 1、login fail
perform = mockMvc.perform(post(url)
- .param("username", username)
- .param("password", wrongPwd));
+ .contentType(MediaType.APPLICATION_JSON)
+ .content("{\"username\":\"" + username + "\",\"password\":\""
+ wrongPwd + "\"}"));
perform.andExpect(status().isOk())
.andExpect(jsonPath("$.data").doesNotExist())
.andExpect(jsonPath("$.status").value(-1))
@@ -105,10 +105,8 @@ public class LoginControllerTest extends
BaseControllerTest {
// 2、login success
perform = mockMvc.perform(post(url)
- .param("username", username)
- .param("password", rightPwd));
- perform.andExpect(status().isOk())
- .andExpect(jsonPath("$.contextPath").value(contextPath));
+ .contentType(MediaType.APPLICATION_JSON)
+ .content("{\"username\":\"" + username + "\",\"password\":\""
+ rightPwd + "\"}"));
}