diff --git a/opentelemetry-prometheus/tests/integration_test.rs b/opentelemetry-prometheus/tests/integration_test.rs index 51aa496b62..149185e440 100644 --- a/opentelemetry-prometheus/tests/integration_test.rs +++ b/opentelemetry-prometheus/tests/integration_test.rs @@ -406,6 +406,7 @@ fn gather_and_compare(registry: prometheus::Registry, expected: String, name: &' let metric_families = registry.gather(); encoder.encode(&metric_families, &mut output).unwrap(); + let expected = get_platform_specific_string(expected); let output_string = get_platform_specific_string(String::from_utf8(output).unwrap()); assert_eq!(output_string, expected, "{name}"); @@ -413,11 +414,10 @@ fn gather_and_compare(registry: prometheus::Registry, expected: String, name: &' /// Returns a String which uses the platform specific new line feed character. fn get_platform_specific_string(input: String) -> String { - if cfg!(windows) { - input.replace('\n', "\r\n") - } else { - input + if cfg!(windows) && !input.ends_with("\r\n") && input.ends_with('\n') { + return input.replace('\n', "\r\n"); } + input } #[test] @@ -812,6 +812,7 @@ fn duplicate_metrics() { .expected_files .into_iter() .map(|f| fs::read_to_string(Path::new("./tests/data").join(f)).expect(f)) + .map(get_platform_specific_string) .collect(); gather_and_compare_multi(registry, possible_matches, tc.name); } diff --git a/opentelemetry-proto/tests/grpc_build.rs b/opentelemetry-proto/tests/grpc_build.rs index 7201a0f8f8..8477a4e626 100644 --- a/opentelemetry-proto/tests/grpc_build.rs +++ b/opentelemetry-proto/tests/grpc_build.rs @@ -18,7 +18,7 @@ const TONIC_INCLUDES: &[&str] = &["src/proto/opentelemetry-proto", "src/proto"]; #[test] fn build_tonic() { - let before_build = build_content_map(TONIC_OUT_DIR, false); + let before_build = build_content_map(TONIC_OUT_DIR, true); let out_dir = TempDir::new().expect("failed to create temp dir to store the generated files"); @@ -130,13 +130,12 @@ fn build_content_map(path: impl AsRef, normalize_line_feed: bool) -> HashM .collect() } -/// Returns a String with the platform specific new line feed character. +/// Returns a String which uses the platform specific new line feed character. fn get_platform_specific_string(input: String) -> String { - if cfg!(windows) { - input.replace('\n', "\r\n") - } else { - input + if cfg!(windows) && !input.ends_with("\r\n") && input.ends_with('\n') { + return input.replace('\n', "\r\n"); } + input } fn ensure_files_are_same(