Skip to content

Commit daaa9cc

Browse files
authored
Merge pull request #90 from http-rs/zero-test
create a long chunked test
2 parents dd1bc1e + c496b79 commit daaa9cc

File tree

5 files changed

+224
-6
lines changed

5 files changed

+224
-6
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ log = "0.4"
2626
pretty_assertions = "0.6.1"
2727
async-std = { version = "1.4.0", features = ["unstable", "attributes"] }
2828
tempfile = "3.1.0"
29+
async-test = "1.0.0"

src/server/encode.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,14 @@ impl Read for Encoder {
225225
// we keep track how many bytes of the head and body we've read
226226
// in this call of `poll_read`
227227
self.bytes_read = 0;
228-
match self.state {
228+
let res = match self.state {
229229
EncoderState::Start => self.encode_start(cx, buf),
230230
EncoderState::Head => self.encode_head(cx, buf),
231231
EncoderState::FixedBody => self.encode_fixed_body(cx, buf),
232232
EncoderState::ChunkedBody => self.encode_chunked_body(cx, buf),
233233
EncoderState::Done => Poll::Ready(Ok(0)),
234-
}
234+
};
235+
// dbg!(String::from_utf8(buf[..self.bytes_read].to_vec()).unwrap());
236+
res
235237
}
236238
}

tests/common/mod.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ impl TestCase {
7171
}
7272
}
7373

74+
#[allow(dead_code)]
7475
pub async fn read_result(&self) -> String {
7576
use async_std::prelude::*;
7677
let mut result = String::new();
@@ -80,6 +81,7 @@ impl TestCase {
8081
result
8182
}
8283

84+
#[allow(dead_code)]
8385
pub async fn read_expected(&self) -> String {
8486
use async_std::prelude::*;
8587
let mut expected = std::string::String::new();
@@ -92,15 +94,16 @@ impl TestCase {
9294
expected
9395
}
9496

97+
#[allow(dead_code)]
9598
pub(crate) async fn assert(self) {
9699
let mut actual = self.read_result().await;
97100
let mut expected = self.read_expected().await;
98101
assert!(!actual.is_empty(), "Received empty reply");
99102
assert!(!expected.is_empty(), "Missing expected fixture");
100103

101104
// munge actual and expected so that we don't rely on dates matching exactly
102-
munge_date(&mut expected, &mut actual);
103-
pretty_assertions::assert_eq!(expected, actual);
105+
munge_date(&mut actual, &mut expected);
106+
pretty_assertions::assert_eq!(actual, expected);
104107
}
105108
}
106109

@@ -109,14 +112,16 @@ pub(crate) fn fixture_path(relative_path: &str) -> PathBuf {
109112
directory.join("tests").join(relative_path)
110113
}
111114

112-
pub(crate) fn munge_date(expected: &mut String, actual: &mut String) {
115+
pub(crate) fn munge_date(actual: &mut String, expected: &mut String) {
113116
if let Some(i) = expected.find("{DATE}") {
114117
match actual.find("date: ") {
115118
Some(j) => {
116119
let eol = actual[j + 6..].find("\r\n").expect("missing eol");
117120
expected.replace_range(i..i + 6, &actual[j + 6..j + 6 + eol]);
118121
}
119-
None => expected.replace_range(i..i + 6, ""),
122+
None => {
123+
expected.replace_range(i..i + 6, "");
124+
}
120125
}
121126
}
122127
}

0 commit comments

Comments
 (0)