[ISSUE #359] Fix fail test in LoginControllerTest and add .env (#363)

* commit

* commit

* commit

* commit
This commit is contained in:
Crazylychee
2025-08-30 19:25:05 +08:00
committed by GitHub
parent 8037cfcf05
commit ce8306a602
5 changed files with 13 additions and 16 deletions

View File

@@ -0,0 +1 @@
REACT_APP_API_BASE_URL=http://localhost:8082

View File

@@ -0,0 +1 @@
REACT_APP_API_BASE_URL=

View File

@@ -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) {

View File

@@ -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'

View File

@@ -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 + "\"}"));
}