Skip to content

Commit 8327c95

Browse files
committed
chore: Unit test update for zstd
1 parent 5204a74 commit 8327c95

File tree

1 file changed

+49
-0
lines changed
  • opentelemetry-otlp/src/exporter/http

1 file changed

+49
-0
lines changed

opentelemetry-otlp/src/exporter/http/mod.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,35 @@ mod tests {
854854
assert_ne!(compressed_body, test_data.to_vec());
855855
}
856856

857+
#[cfg(feature = "zstd-http")]
858+
#[test]
859+
fn test_zstd_compression_and_decompression() {
860+
let client = OtlpHttpClient::new(
861+
std::sync::Arc::new(MockHttpClient),
862+
"http://localhost:4318".parse().unwrap(),
863+
std::collections::HashMap::new(),
864+
crate::Protocol::HttpBinary,
865+
std::time::Duration::from_secs(10),
866+
Some(crate::Compression::Zstd),
867+
);
868+
869+
// Test with some sample data
870+
let test_data = b"Hello, world! This is test data for zstd compression.";
871+
let result = client.compress_body(test_data.to_vec()).unwrap();
872+
let (compressed_body, content_encoding) = result;
873+
874+
// Verify encoding header is set
875+
assert_eq!(content_encoding, Some("zstd"));
876+
877+
// Verify we can decompress the body
878+
let decompressed = zstd::bulk::decompress(&compressed_body, test_data.len()).unwrap();
879+
880+
// Verify decompressed data matches original
881+
assert_eq!(decompressed, test_data);
882+
// Verify compression actually happened (compressed should be different)
883+
assert_ne!(compressed_body, test_data.to_vec());
884+
}
885+
857886
#[test]
858887
fn test_no_compression_when_disabled() {
859888
let client = OtlpHttpClient::new(
@@ -894,6 +923,26 @@ mod tests {
894923
assert!(result.unwrap_err().contains("gzip-http feature not enabled"));
895924
}
896925

926+
#[cfg(not(feature = "zstd-http"))]
927+
#[test]
928+
fn test_zstd_error_when_feature_disabled() {
929+
let client = OtlpHttpClient::new(
930+
std::sync::Arc::new(MockHttpClient),
931+
"http://localhost:4318".parse().unwrap(),
932+
std::collections::HashMap::new(),
933+
crate::Protocol::HttpBinary,
934+
std::time::Duration::from_secs(10),
935+
Some(crate::Compression::Zstd),
936+
);
937+
938+
let body = vec![1, 2, 3, 4];
939+
let result = client.compress_body(body);
940+
941+
// Should return error when zstd requested but feature not enabled
942+
assert!(result.is_err());
943+
assert!(result.unwrap_err().contains("zstd-http feature not enabled"));
944+
}
945+
897946
// Mock HTTP client for testing
898947
#[derive(Debug)]
899948
struct MockHttpClient;

0 commit comments

Comments
 (0)