Skip to content

Commit 9bbce12

Browse files
authored
test: Nit test addition to otlp (#3390)
1 parent 8ac4e67 commit 9bbce12

File tree

1 file changed

+92
-0
lines changed
  • opentelemetry-otlp/src/exporter/tonic

1 file changed

+92
-0
lines changed

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

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,4 +962,96 @@ mod tests {
962962
result.unwrap_err()
963963
);
964964
}
965+
966+
#[test]
967+
#[cfg(not(feature = "gzip-tonic"))]
968+
fn test_gzip_compression_errors_without_feature() {
969+
use crate::exporter::ExporterBuildError;
970+
use crate::SpanExporter;
971+
use crate::WithTonicConfig;
972+
973+
let result = SpanExporter::builder()
974+
.with_tonic()
975+
.with_compression(crate::Compression::Gzip)
976+
.build();
977+
978+
assert!(result.is_err());
979+
let err = result.unwrap_err();
980+
assert!(
981+
matches!(
982+
err,
983+
ExporterBuildError::FeatureRequiredForCompressionAlgorithm(..)
984+
),
985+
"expected FeatureRequiredForCompressionAlgorithm error, got: {err:?}"
986+
);
987+
let msg = err.to_string();
988+
assert!(
989+
msg.contains("gzip-tonic"),
990+
"error message should mention 'gzip-tonic' feature, got: {msg}"
991+
);
992+
}
993+
994+
#[tokio::test]
995+
#[cfg(feature = "gzip-tonic")]
996+
async fn test_gzip_compression_succeeds_with_feature() {
997+
use crate::SpanExporter;
998+
use crate::WithTonicConfig;
999+
1000+
let result = SpanExporter::builder()
1001+
.with_tonic()
1002+
.with_compression(crate::Compression::Gzip)
1003+
.build();
1004+
1005+
assert!(
1006+
result.is_ok(),
1007+
"gzip compression should succeed when gzip-tonic feature is enabled, got: {:?}",
1008+
result.unwrap_err()
1009+
);
1010+
}
1011+
1012+
#[test]
1013+
#[cfg(not(feature = "zstd-tonic"))]
1014+
fn test_zstd_compression_errors_without_feature() {
1015+
use crate::exporter::ExporterBuildError;
1016+
use crate::SpanExporter;
1017+
use crate::WithTonicConfig;
1018+
1019+
let result = SpanExporter::builder()
1020+
.with_tonic()
1021+
.with_compression(crate::Compression::Zstd)
1022+
.build();
1023+
1024+
assert!(result.is_err());
1025+
let err = result.unwrap_err();
1026+
assert!(
1027+
matches!(
1028+
err,
1029+
ExporterBuildError::FeatureRequiredForCompressionAlgorithm(..)
1030+
),
1031+
"expected FeatureRequiredForCompressionAlgorithm error, got: {err:?}"
1032+
);
1033+
let msg = err.to_string();
1034+
assert!(
1035+
msg.contains("zstd-tonic"),
1036+
"error message should mention 'zstd-tonic' feature, got: {msg}"
1037+
);
1038+
}
1039+
1040+
#[tokio::test]
1041+
#[cfg(feature = "zstd-tonic")]
1042+
async fn test_zstd_compression_succeeds_with_feature() {
1043+
use crate::SpanExporter;
1044+
use crate::WithTonicConfig;
1045+
1046+
let result = SpanExporter::builder()
1047+
.with_tonic()
1048+
.with_compression(crate::Compression::Zstd)
1049+
.build();
1050+
1051+
assert!(
1052+
result.is_ok(),
1053+
"zstd compression should succeed when zstd-tonic feature is enabled, got: {:?}",
1054+
result.unwrap_err()
1055+
);
1056+
}
9651057
}

0 commit comments

Comments
 (0)