LCOV - code coverage report
Current view: top level - proxy/src/redis - keys.rs (source / functions) Coverage Total Hit
Test: 1e20c4f2b28aa592527961bb32170ebbd2c9172f.info Lines: 100.0 % 12 12
Test Date: 2025-07-16 12:29:03 Functions: 100.0 % 2 2

            Line data    Source code
       1              : use crate::pqproto::CancelKeyData;
       2              : 
       3              : pub mod keyspace {
       4              :     pub const CANCEL_PREFIX: &str = "cancel";
       5              : }
       6              : 
       7              : #[derive(Clone, Debug, Eq, PartialEq)]
       8              : pub(crate) enum KeyPrefix {
       9              :     Cancel(CancelKeyData),
      10              : }
      11              : 
      12              : impl KeyPrefix {
      13            1 :     pub(crate) fn build_redis_key(&self) -> String {
      14            1 :         match self {
      15            1 :             KeyPrefix::Cancel(key) => {
      16            1 :                 let id = key.0.get();
      17            1 :                 let keyspace = keyspace::CANCEL_PREFIX;
      18            1 :                 format!("{keyspace}:{id:x}")
      19              :             }
      20              :         }
      21            1 :     }
      22              : }
      23              : 
      24              : #[cfg(test)]
      25              : mod tests {
      26              :     use super::*;
      27              :     use crate::pqproto::id_to_cancel_key;
      28              : 
      29              :     #[test]
      30            1 :     fn test_build_redis_key() {
      31            1 :         let cancel_key: KeyPrefix = KeyPrefix::Cancel(id_to_cancel_key(12345 << 32 | 54321));
      32              : 
      33            1 :         let redis_key = cancel_key.build_redis_key();
      34            1 :         assert_eq!(redis_key, "cancel:30390000d431");
      35            1 :     }
      36              : }
        

Generated by: LCOV version 2.1-beta