Skip to content

Commit c7b1dea

Browse files
author
Drew Robinson
committed
Add minimal postcard migration smoke tests
Verify the bincode → postcard migration works correctly with targeted tests for Value roundtrips and error conversion.
1 parent 908d921 commit c7b1dea

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

libsql-server/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ mod query;
8787
mod query_analysis;
8888
mod query_result_builder;
8989
mod replication;
90+
#[cfg(test)]
91+
mod rpc_postcard_tests;
9092
mod schema;
9193
mod stats;
9294
#[cfg(test)]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#![cfg(test)]
2+
3+
//! Minimal smoke tests for postcard serialisation.
4+
//! These verify the bincode → postcard migration works correctly.
5+
6+
use crate::query::Value;
7+
8+
/// Verify roundtrip works for all Value variants.
9+
#[test]
10+
fn test_value_roundtrip_all_variants() {
11+
let values = vec![
12+
Value::Null,
13+
Value::Integer(0),
14+
Value::Integer(i64::MAX),
15+
Value::Integer(i64::MIN),
16+
Value::Real(std::f64::consts::PI),
17+
Value::Real(f64::MAX),
18+
Value::Text(String::new()),
19+
Value::Text("hello 🦀".to_string()),
20+
Value::Blob(vec![]),
21+
Value::Blob(vec![0u8, 255u8]),
22+
];
23+
24+
for value in &values {
25+
let encoded = postcard::to_stdvec(value).expect("encode failed");
26+
let decoded: Value = postcard::from_bytes(&encoded).expect("decode failed");
27+
assert_eq!(format!("{:?}", value), format!("{:?}", decoded));
28+
}
29+
}
30+
31+
/// Verify large blobs don't hit size limits.
32+
#[test]
33+
fn test_large_blob_roundtrip() {
34+
let value = Value::Blob(vec![42u8; 1_000_000]);
35+
let encoded = postcard::to_stdvec(&value).expect("encode failed");
36+
let decoded: Value = postcard::from_bytes(&encoded).expect("decode failed");
37+
assert!(matches!(decoded, Value::Blob(b) if b.len() == 1_000_000));
38+
}
39+
40+
/// Verify postcard errors convert correctly to our error type.
41+
#[test]
42+
fn test_postcard_error_conversion() {
43+
let garbage = vec![0xff, 0xfe];
44+
let result: Result<Value, postcard::Error> = postcard::from_bytes(&garbage);
45+
46+
if let Err(e) = result {
47+
let crate_error = crate::error::Error::from(e);
48+
assert!(
49+
matches!(crate_error, crate::error::Error::Internal(msg) if msg.contains("Unexpected"))
50+
);
51+
}
52+
}

0 commit comments

Comments
 (0)