From c51293b4e0c1591f4992571e808f388e47172078 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 17 Mar 2026 16:10:00 -0700 Subject: [PATCH] Add TTL normalization tests for Go parity verification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test that fit_ttl_count normalizes 120m→2h, 24h→1d, 7d→1w even when count fits in a byte, matching Go's fitTtlCount behavior. --- seaweed-volume/src/storage/needle/ttl.rs | 34 ++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/seaweed-volume/src/storage/needle/ttl.rs b/seaweed-volume/src/storage/needle/ttl.rs index 7aadb73e2..f44a8c782 100644 --- a/seaweed-volume/src/storage/needle/ttl.rs +++ b/seaweed-volume/src/storage/needle/ttl.rs @@ -272,4 +272,38 @@ mod tests { } ); } + + #[test] + fn test_ttl_normalization_under_256() { + // 120 minutes should normalize to 2 hours (matches Go fitTtlCount behavior). + // Even though count=120 fits in a byte, Go always normalizes to the coarsest unit. + let ttl = TTL::read("120m").unwrap(); + assert_eq!( + ttl, + TTL { + count: 2, + unit: TTL_UNIT_HOUR + } + ); + + // 24 hours should normalize to 1 day + let ttl = TTL::read("24h").unwrap(); + assert_eq!( + ttl, + TTL { + count: 1, + unit: TTL_UNIT_DAY + } + ); + + // 7 days should normalize to 1 week + let ttl = TTL::read("7d").unwrap(); + assert_eq!( + ttl, + TTL { + count: 1, + unit: TTL_UNIT_WEEK + } + ); + } }