()
| 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 | } |
nothing calls this directly
no test coverage detected