Repository: tikv/tikv
File: components/backup-stream/src/router.rs (Rust)

Code before:

    fn events_to_kv_pair(apply_events: &ApplyEvents) -> Vec<(Vec<u8>, Vec<u8>)> {
        let mut kv_pairs = Vec::new();
        for apply_event in &apply_events.events {
            kv_pairs.push((apply_event.key.clone(), apply_event.value.clone()));
        }
        kv_pairs
    }

    #[test]
    fn test_path_to_meta() {
        let mut meta = MetadataInfo::with_capacity(0);
        meta.min_ts = Some(100);
        meta.max_ts = Some(200);

        // Case 1: Normal flush_ts
        let path = meta.path_to_meta(50, 300);
        assert_eq!(
            path,
            "v1/backupmeta/000000000000012C-0000000000000032-0000000000000064-00000000000000C8.meta"
        );

        // Case 2: flush_ts is 0
        let path_synthetic = meta.path_to_meta(50, 0);
        let another_path_synthetic = meta.path_to_meta(50, 0);
        // synthetic path shouldn't be the same.
        assert_ne!(another_path_synthetic, path_synthetic);

        assert!(path_synthetic.contains("-SYNTHETIC"));
        assert!(path_synthetic.starts_with("v1/backupmeta/"));
        assert!(path_synthetic.ends_with(".meta"));

        // Check that the timestamp part is not 0 anymore (it uses physical_now)
        let parts: Vec<&str> = path_synthetic.split('/').collect();
        let filename = parts.last().unwrap();
        let ts_part = filename.split('-').next().unwrap();
        let ts = u64::from_str_radix(ts_part, 16).unwrap();
        assert_ne!(ts, 0);
    }
}


Review comment (suggestion):
The test assertion comment is slightly unclear. Consider rephrasing to "synthetic paths should be unique due to different UUIDs" for better clarity.
```suggestion
        // synthetic paths should be unique due to different UUIDs
```

Code after:
        let mut kv_pairs = Vec::new();
        for apply_event in &apply_events.events {
            kv_pairs.push((apply_event.key.clone(), apply_event.value.clone()));
        }
        kv_pairs
    }

    #[test]
    fn test_path_to_meta() {
        let mut meta = MetadataInfo::with_capacity(0);
        meta.min_ts = Some(100);
        meta.max_ts = Some(200);

        // Case 1: Normal flush_ts
        let path = meta.path_to_meta(50, 300);
        assert_eq!(
            path,
            "v1/backupmeta/000000000000012C-0000000000000032-0000000000000064-00000000000000C8.meta"
        );

        // Case 2: flush_ts is 0
        let path_synthetic = meta.path_to_meta(50, 0);
        let another_path_synthetic = meta.path_to_meta(50, 0);
        // synthetic paths should be unique due to different UUIDs
        assert_ne!(another_path_synthetic, path_synthetic);

        // Verify the synthetic path format with regex
        let synthetic_pattern = regex::Regex::new(
            r"^v1/backupmeta/([0-9A-F]{16})-[0-9A-F]{16}-[0-9A-F]{16}-[0-9A-F]{16}-SYNTHETIC[0-9A-F]+\.meta$"
        ).unwrap();
        let capture = synthetic_pattern
            .captures(&path_synthetic)
            .unwrap_or_else(|| panic!("non match: {}", path_synthetic));

        // Check that the timestamp part is not 0 anymore (it uses physical_now)
        let ts = u64::from_str_radix(capture.get(1).unwrap().as_str(), 16).unwrap();
        assert_ne!(ts, 0);
    }
}