Skip to content

Commit c449528

Browse files
authored
test(body): add proper cfgs to body unit tests (#3864)
Running `cargo test` fails to compile because tests rely on types which are behind a #[cfg(…)] which is disabled by default. Add a #[cfg(…)] directive to tests which rely on types which are also behind a #[cfg(…)] directive, so that these tests run only if the types on which they depend exist.
1 parent 68bae2b commit c449528

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/body/incoming.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ impl Incoming {
103103
/// Create a `Body` stream with an associated sender half.
104104
///
105105
/// Useful when wanting to stream chunks from another thread.
106+
#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))]
106107
#[inline]
107108
#[cfg(test)]
108109
pub(crate) fn channel() -> (Sender, Incoming) {
@@ -460,9 +461,12 @@ mod tests {
460461
use std::mem;
461462
use std::task::Poll;
462463

463-
use super::{Body, DecodedLength, Incoming, Sender, SizeHint};
464+
use super::{Body, Incoming, SizeHint};
465+
#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))]
466+
use super::{DecodedLength, Sender};
464467
use http_body_util::BodyExt;
465468

469+
#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))]
466470
#[test]
467471
fn test_size_of() {
468472
// These are mostly to help catch *accidentally* increasing
@@ -492,6 +496,7 @@ mod tests {
492496
);
493497
}
494498

499+
#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))]
495500
#[test]
496501
fn size_hint() {
497502
fn eq(body: Incoming, b: SizeHint, note: &str) {
@@ -511,6 +516,7 @@ mod tests {
511516
);
512517
}
513518

519+
#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))]
514520
#[cfg(not(miri))]
515521
#[tokio::test]
516522
async fn channel_abort() {
@@ -522,6 +528,7 @@ mod tests {
522528
assert!(err.is_body_write_aborted(), "{:?}", err);
523529
}
524530

531+
#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))]
525532
#[cfg(all(not(miri), feature = "http1"))]
526533
#[tokio::test]
527534
async fn channel_abort_when_buffer_is_full() {
@@ -556,6 +563,7 @@ mod tests {
556563
assert_eq!(chunk2, "chunk 2");
557564
}
558565

566+
#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))]
559567
#[cfg(not(miri))]
560568
#[tokio::test]
561569
async fn channel_empty() {
@@ -564,6 +572,7 @@ mod tests {
564572
assert!(rx.frame().await.is_none());
565573
}
566574

575+
#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))]
567576
#[test]
568577
fn channel_ready() {
569578
let (mut tx, _rx) = Incoming::new_channel(DecodedLength::CHUNKED, /*wanter = */ false);
@@ -573,6 +582,7 @@ mod tests {
573582
assert!(tx_ready.poll().is_ready(), "tx is ready immediately");
574583
}
575584

585+
#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))]
576586
#[test]
577587
fn channel_wanter() {
578588
let (mut tx, mut rx) =
@@ -595,6 +605,7 @@ mod tests {
595605
);
596606
}
597607

608+
#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))]
598609
#[test]
599610
fn channel_notices_closure() {
600611
let (mut tx, rx) = Incoming::new_channel(DecodedLength::CHUNKED, /*wanter = */ true);

0 commit comments

Comments
 (0)