You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use super::*;
use crate::protocol::stomp::*;
#[test]
fn test_check_stomp_client_connect_request_valid() {
// 准备符合 STOMP 协议的请求数据
let data = b"CONNECT\n\n\0";
let mut state = ProtocolInspectState::new();
let result = state.check_stomp_client_connect_request(data);
assert!(result.is_ok());
assert_eq!(result.unwrap(), Some(Protocol::Stomp));
}
#[test]
fn test_check_stomp_client_connect_request_invalid() {
// 准备不符合 STOMP 协议的请求数据
let data = b"INVALID_REQUEST";
let mut state = ProtocolInspectState::new();
let result = state.check_stomp_client_connect_request(data);
assert!(result.is_ok());
assert_eq!(result.unwrap(), None);
}
#[test]
fn test_check_stomp_client_connect_request_need_more_data() {
// 准备长度不足的请求数据
let data = b"CO";
let mut state = ProtocolInspectState::new();
let result = state.check_stomp_client_connect_request(data);
assert!(result.is_err());
assert!(matches!(result.unwrap_err(), ProtocolInspectError::NeedMoreData(_)));
}
// 为 check_stomp_connect_method 和 check_stomp_stomp_method 编写类似的测试用例
注意事项
确保测试用例的独立性,每个测试用例应该能够独立运行,不依赖于其他测试用例的状态。
测试用例的命名应该清晰明了,能够准确反映测试的场景。
可以根据需要添加更多的测试用例,以覆盖更多的边界情况。
提交要求
提交的代码应遵循项目的代码风格和规范。
The text was updated successfully, but these errors were encountered:
问题描述
当前项目中
lib/g3-dpi/src/protocol/stomp.rs
文件实现了 STOMP 协议的检查逻辑,但缺少对应的单元测试。需要在lib/g3-dpi/tests
目录下添加单元测试,以确保STOMP协议识别的正确性。任务要求
tests
目录下创建一个新的测试文件stomp.rs
。ProtocolInspectState
中的以下方法编写单元测试:check_stomp_client_connect_request
Protocol::Stomp
。Ok(None)
。Err(ProtocolInspectError::NeedMoreData)
。示例代码结构(AI生成,仅供参考)
注意事项
提交要求
The text was updated successfully, but these errors were encountered: