MCPcopy Create free account
hub / github.com/chirpstack/chirpstack / test_log_request

Function test_log_request

chirpstack/src/stream/api_request.rs:39–72  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

37
38 #[tokio::test]
39 async fn test_log_request() {
40 let _guard = test::prepare().await;
41
42 let pl = stream::ApiRequestLog {
43 service: "ap.Foo".to_string(),
44 method: "bar".to_string(),
45 metadata: [("user_id".to_string(), "foo_user".to_string())]
46 .iter()
47 .cloned()
48 .collect(),
49 };
50 log_request(&pl).await.unwrap();
51
52 let key = redis_key("api:stream:request".to_string());
53 let srr: StreamReadReply = redis::cmd("XREAD")
54 .arg("COUNT")
55 .arg(1_usize)
56 .arg("STREAMS")
57 .arg(&key)
58 .arg("0")
59 .query_async(&mut get_async_redis_conn().await.unwrap())
60 .await
61 .unwrap();
62
63 assert_eq!(1, srr.keys.len());
64 assert_eq!(1, srr.keys[0].ids.len());
65
66 if let Some(redis::Value::BulkString(b)) = srr.keys[0].ids[0].map.get("request") {
67 let pl_recv = stream::ApiRequestLog::decode(&mut Cursor::new(b)).unwrap();
68 assert_eq!(pl, pl_recv);
69 } else {
70 panic!("No request log");
71 }
72 }
73}

Callers

nothing calls this directly

Calls 9

prepareFunction · 0.85
redis_keyFunction · 0.85
get_async_redis_connFunction · 0.85
to_stringMethod · 0.80
iterMethod · 0.80
unwrapMethod · 0.80
log_requestFunction · 0.70
decodeFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected