Skip to content

Commit 8d5f6ee

Browse files
committed
test: add test for parsing client id
Signed-off-by: Anthony Griffon <[email protected]>
1 parent 86440c5 commit 8d5f6ee

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed

app/roster/src/application/server/cmd/client/id.rs

+37
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,40 @@ impl ClientID {
4343
Ok(())
4444
}
4545
}
46+
47+
#[cfg(test)]
48+
mod tests {
49+
use std::io::Cursor;
50+
51+
use bytes::BytesMut;
52+
use redis_async::resp::{RespCodec, RespValue};
53+
use redis_async::resp_array;
54+
use tokio_util::codec::Encoder;
55+
56+
use crate::application::server::cmd::Command;
57+
use crate::application::server::frame::Frame;
58+
59+
fn parse_cmd(obj: RespValue) -> anyhow::Result<Command> {
60+
let mut bytes = BytesMut::new();
61+
let mut codec = RespCodec;
62+
codec.encode(obj, &mut bytes).unwrap();
63+
64+
let mut bytes = Cursor::new(bytes.freeze());
65+
let frame = Frame::parse(&mut bytes)?;
66+
let client_list = Command::from_frame(frame)?;
67+
Ok(client_list)
68+
}
69+
70+
#[test]
71+
fn ensure_parsing() {
72+
let entry: RespValue = resp_array!["CLIENT", "ID"];
73+
let client_cmd = parse_cmd(entry).unwrap();
74+
insta::assert_debug_snapshot!(client_cmd, @r###"
75+
Client(
76+
Id(
77+
ClientID,
78+
),
79+
)
80+
"###);
81+
}
82+
}

app/roster/src/application/server/cmd/client/list.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,14 @@ impl ClientList {
9999
dst: &mut WriteConnection,
100100
ctx: Context,
101101
) -> anyhow::Result<()> {
102+
/*
102103
let id = ctx.connection.id();
103104
104105
let response = Frame::Integer(id);
105106
dst.write_frame(&response).await?;
106-
107107
Ok(())
108+
*/
109+
unimplemented!()
108110
}
109111
}
110112

@@ -139,7 +141,7 @@ mod tests {
139141
Client(
140142
List(
141143
ClientList {
142-
type: NORMAL,
144+
type: Normal,
143145
ids: Some(
144146
[],
145147
),
@@ -157,7 +159,7 @@ mod tests {
157159
Client(
158160
List(
159161
ClientList {
160-
type: NORMAL,
162+
type: Normal,
161163
ids: Some(
162164
[],
163165
),
@@ -175,7 +177,7 @@ mod tests {
175177
Client(
176178
List(
177179
ClientList {
178-
type: MASTER,
180+
type: Master,
179181
ids: Some(
180182
[],
181183
),
@@ -193,7 +195,7 @@ mod tests {
193195
Client(
194196
List(
195197
ClientList {
196-
type: REPLICA,
198+
type: Replica,
197199
ids: Some(
198200
[],
199201
),
@@ -211,7 +213,7 @@ mod tests {
211213
Client(
212214
List(
213215
ClientList {
214-
type: PUBSUB,
216+
type: Pubsub,
215217
ids: Some(
216218
[],
217219
),
@@ -242,7 +244,7 @@ mod tests {
242244
Client(
243245
List(
244246
ClientList {
245-
type: NORMAL,
247+
type: Normal,
246248
ids: Some(
247249
[
248250
1,

0 commit comments

Comments
 (0)