@@ -854,6 +854,35 @@ mod tests {
854
854
assert_ne ! ( compressed_body, test_data. to_vec( ) ) ;
855
855
}
856
856
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
+
857
886
#[ test]
858
887
fn test_no_compression_when_disabled ( ) {
859
888
let client = OtlpHttpClient :: new (
@@ -894,6 +923,26 @@ mod tests {
894
923
assert ! ( result. unwrap_err( ) . contains( "gzip-http feature not enabled" ) ) ;
895
924
}
896
925
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
+
897
946
// Mock HTTP client for testing
898
947
#[ derive( Debug ) ]
899
948
struct MockHttpClient ;
0 commit comments