mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-23 03:19:41 +00:00
* 让 CI 真正跑起三类测试并修掉挡路的测试缺陷 之前 CI 只跑了一小部分,Java 那边的测试被 pom 里的开关整个跳过了。 这条把它打开,并补上 MySQL、Redis 两个容器,Java、契约、Python 三类 测试都在 CI 里真跑起来。 另外修了两个挡路的地方:一条 Java 用例单跑会因为实体信息没注册而报错, 现在自己注册;Python 的假网络层把整个 httpx 类换掉了,第三方库拼请求 时报错,改成只换发请求那一步。 * 给 runner 补上 libopus,修掉音频用例报错 opuslib_next 是 ctypes 绑定,真正编解码靠系统里的 libopus。runner 上默认 没有,import 失败后测试里换上的是自己写的桩,桩里的编码器只有构造方法, 一调就报错。正式镜像里是装了这个库的,CI 少了这一步。 顺手把桩的报错改成一句人话,别再让人对着缺方法的报错猜根因。 * 本地没起库也能构建,CI 里集成测试不许跳过 三个要连 MySQL 和 Redis 的集成测试加了守卫:依赖连不上就整类跳过,日志写明缺什么,构建照样是绿的;CI 上依赖不通就直接失败。另外加了一个门禁检查脚本和 CI 步骤,盯住这三个类有没有真跑,守卫哪天手滑把它们全跳过了,CI 必须变红。README 里补了本地怎么起依赖、怎么只编译不跑测试。
79 lines
2.6 KiB
Java
79 lines
2.6 KiB
Java
package xiaozhi.modules.sys;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
import static org.mockito.Mockito.when;
|
|
|
|
import org.junit.jupiter.api.BeforeAll;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.test.context.ActiveProfiles;
|
|
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import xiaozhi.common.exception.ErrorCode;
|
|
import xiaozhi.common.exception.RenException;
|
|
import xiaozhi.modules.security.controller.LoginController;
|
|
import xiaozhi.modules.security.dto.LoginDTO;
|
|
import xiaozhi.modules.security.dto.SmsVerificationDTO;
|
|
import xiaozhi.modules.sys.dto.RetrievePasswordDTO;
|
|
import xiaozhi.modules.sys.service.SysUserService;
|
|
import xiaozhi.testsupport.IntegrationTestEnvironment;
|
|
|
|
@Slf4j
|
|
@SpringBootTest
|
|
@ActiveProfiles("dev")
|
|
class loginControllerTest {
|
|
|
|
@BeforeAll
|
|
static void checkDependencies() {
|
|
IntegrationTestEnvironment.requireDatabaseAndRedis();
|
|
}
|
|
|
|
@Autowired
|
|
LoginController loginController;
|
|
|
|
@MockitoBean
|
|
SysUserService sysUserService;
|
|
|
|
@Test
|
|
public void testRegister() {
|
|
when(sysUserService.getAllowUserRegister()).thenReturn(false);
|
|
|
|
LoginDTO loginDTO = new LoginDTO();
|
|
loginDTO.setUsername("手机号码");
|
|
loginDTO.setPassword("密码");
|
|
|
|
RenException exception = assertThrows(RenException.class, () -> loginController.register(loginDTO));
|
|
assertEquals(ErrorCode.USER_REGISTER_DISABLED, exception.getCode());
|
|
}
|
|
|
|
@Test
|
|
public void testSmsVerification() {
|
|
try {
|
|
SmsVerificationDTO smsVerificationDTO = new SmsVerificationDTO();
|
|
smsVerificationDTO.setPhone("手机号码");
|
|
smsVerificationDTO.setCaptchaId("123456");
|
|
smsVerificationDTO.setCaptcha("123456");
|
|
loginController.smsVerification(smsVerificationDTO);
|
|
} catch (Exception e) {
|
|
System.out.println(e.getMessage());
|
|
}
|
|
}
|
|
|
|
@Test
|
|
public void testRetrievePassword() {
|
|
try {
|
|
RetrievePasswordDTO retrievePasswordDTO = new RetrievePasswordDTO();
|
|
retrievePasswordDTO.setCode("123456");
|
|
retrievePasswordDTO.setPhone("手机号码");
|
|
retrievePasswordDTO.setPassword("密码");
|
|
loginController.retrievePassword(retrievePasswordDTO);
|
|
} catch (Exception e) {
|
|
System.out.println(e.getMessage());
|
|
}
|
|
|
|
}
|
|
|
|
}
|