Skip to content

Commit 10d7002

Browse files
committed
test(decompression-plz): moved unit tests to integration tests
1 parent 6c79bbf commit 10d7002

File tree

2 files changed

+103
-152
lines changed

2 files changed

+103
-152
lines changed

decompression-plz/src/state.rs

Lines changed: 0 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -177,154 +177,3 @@ where
177177
}
178178
}
179179
}
180-
181-
/*
182-
#[cfg(test)]
183-
mod tests {
184-
185-
use crate::{
186-
DecompressTrait,
187-
state::DecodeState,
188-
tests::{INPUT, single_compression},
189-
};
190-
191-
192-
// CE only
193-
fn assert_decode_state_ce_only_single(content_encoding: ContentEncoding) {
194-
let body = single_compression(&content_encoding);
195-
let headers = format!(
196-
"Host: example.com\r\n\
197-
Content-Type: text/html; charset=utf-8\r\n\
198-
Content-Encoding: {}\r\n\
199-
Content-Length: {}\r\n\r\n",
200-
content_encoding.as_ref(),
201-
body.len()
202-
);
203-
let mut tm = TestMessage::build(
204-
headers.as_bytes().into(),
205-
Body::Raw(body.as_slice().into()),
206-
None,
207-
);
208-
209-
let mut buf = BytesMut::new();
210-
let mut state = DecodeState::init(&mut tm, &mut buf);
211-
state = state.try_next().unwrap();
212-
assert!(matches!(state, DecodeState::ContentEncoding(_, _)));
213-
214-
state = state.try_next().unwrap();
215-
assert!(matches!(state, DecodeState::UpdateContentLength(_)));
216-
217-
state = state.try_next().unwrap();
218-
assert!(matches!(state, DecodeState::End));
219-
220-
let result = tm.into_bytes();
221-
let verify = "Host: example.com\r\n\
222-
Content-Type: text/html; charset=utf-8\r\n\
223-
Content-Length: 11\r\n\r\n\
224-
hello world";
225-
assert_eq!(result, verify);
226-
}
227-
228-
#[test]
229-
fn test_decode_state_ce_only_brotli() {
230-
assert_decode_state_ce_only_single(ContentEncoding::Brotli);
231-
}
232-
233-
#[test]
234-
fn test_decode_state_ce_only_compress() {
235-
assert_decode_state_ce_only_single(ContentEncoding::Compress);
236-
}
237-
238-
#[test]
239-
fn test_decode_state_ce_only_deflate() {
240-
assert_decode_state_ce_only_single(ContentEncoding::Deflate);
241-
}
242-
243-
#[test]
244-
fn test_decode_state_ce_only_gzip() {
245-
assert_decode_state_ce_only_single(ContentEncoding::Gzip);
246-
}
247-
248-
#[test]
249-
fn test_decode_state_ce_only_identity() {
250-
assert_decode_state_ce_only_single(ContentEncoding::Identity);
251-
}
252-
253-
#[test]
254-
fn test_decode_state_ce_only_zstd() {
255-
assert_decode_state_ce_only_single(ContentEncoding::Zstd);
256-
}
257-
258-
// TE only
259-
fn assert_decode_state_te_only_single(content_encoding: ContentEncoding) {
260-
let body = single_compression(&content_encoding);
261-
let headers = format!(
262-
"Host: example.com\r\n\
263-
Content-Type: text/html; charset=utf-8\r\n\
264-
Transfer-Encoding: {}\r\n\
265-
Content-Length: {}\r\n\r\n",
266-
content_encoding.as_ref(),
267-
body.len()
268-
);
269-
let mut tm = TestMessage::build(
270-
headers.as_bytes().into(),
271-
Body::Raw(body.as_slice().into()),
272-
None,
273-
);
274-
275-
let mut buf = BytesMut::new();
276-
let mut state = DecodeState::init(&mut tm, &mut buf);
277-
state = state.try_next().unwrap();
278-
assert!(matches!(state, DecodeState::TransferEncoding(_, _)));
279-
280-
state = state.try_next().unwrap();
281-
assert!(matches!(state, DecodeState::UpdateContentLength(_)));
282-
283-
state = state.try_next().unwrap();
284-
assert!(matches!(state, DecodeState::End));
285-
286-
let result = tm.into_bytes();
287-
let verify = "Host: example.com\r\n\
288-
Content-Type: text/html; charset=utf-8\r\n\
289-
Content-Length: 11\r\n\r\n\
290-
hello world";
291-
assert_eq!(result, verify);
292-
}
293-
294-
#[test]
295-
fn test_decode_state_te_only_brotli() {
296-
assert_decode_state_te_only_single(ContentEncoding::Brotli);
297-
}
298-
299-
#[test]
300-
fn test_decode_state_te_only_chunked() {
301-
()
302-
}
303-
304-
#[test]
305-
fn test_decode_state_te_only_compress() {
306-
assert_decode_state_te_only_single(ContentEncoding::Compress);
307-
}
308-
309-
#[test]
310-
fn test_decode_state_te_only_deflate() {
311-
assert_decode_state_te_only_single(ContentEncoding::Deflate);
312-
}
313-
314-
#[test]
315-
fn test_decode_state_te_only_gzip() {
316-
assert_decode_state_te_only_single(ContentEncoding::Gzip);
317-
}
318-
319-
#[test]
320-
fn test_decode_state_te_only_identity() {
321-
assert_decode_state_te_only_single(ContentEncoding::Identity);
322-
}
323-
324-
#[test]
325-
fn test_decode_state_te_only_zstd() {
326-
assert_decode_state_te_only_single(ContentEncoding::Zstd);
327-
}
328-
329-
}
330-
*/

decompression-plz/tests/test_cases/single_compression.rs

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,113 @@ fn run_case(case: &Case, content_encoding: ContentEncoding) {
3737
assert_eq!(result, verify);
3838
}
3939

40+
// Transfer-Encoding
41+
4042
#[test]
41-
fn assert_decode_states_single() {
43+
fn assert_decode_state_single_te_brotli() {
4244
let case = Case {
4345
header_name: "Transfer-Encoding",
4446
expected_state: |s| matches!(s, DecodeState::TransferEncoding(_, _)),
4547
};
4648
run_case(&case, ContentEncoding::Brotli);
4749
}
50+
51+
#[test]
52+
fn assert_decode_state_single_te_compress() {
53+
let case = Case {
54+
header_name: "Transfer-Encoding",
55+
expected_state: |s| matches!(s, DecodeState::TransferEncoding(_, _)),
56+
};
57+
run_case(&case, ContentEncoding::Compress);
58+
}
59+
60+
#[test]
61+
fn assert_decode_state_single_te_deflate() {
62+
let case = Case {
63+
header_name: "Transfer-Encoding",
64+
expected_state: |s| matches!(s, DecodeState::TransferEncoding(_, _)),
65+
};
66+
run_case(&case, ContentEncoding::Deflate);
67+
}
68+
69+
#[test]
70+
fn assert_decode_state_single_te_gzip() {
71+
let case = Case {
72+
header_name: "Transfer-Encoding",
73+
expected_state: |s| matches!(s, DecodeState::TransferEncoding(_, _)),
74+
};
75+
run_case(&case, ContentEncoding::Gzip);
76+
}
77+
78+
#[test]
79+
fn assert_decode_state_single_te_identity() {
80+
let case = Case {
81+
header_name: "Transfer-Encoding",
82+
expected_state: |s| matches!(s, DecodeState::TransferEncoding(_, _)),
83+
};
84+
run_case(&case, ContentEncoding::Identity);
85+
}
86+
87+
#[test]
88+
fn assert_decode_state_single_te_zstd() {
89+
let case = Case {
90+
header_name: "Transfer-Encoding",
91+
expected_state: |s| matches!(s, DecodeState::TransferEncoding(_, _)),
92+
};
93+
run_case(&case, ContentEncoding::Zstd);
94+
}
95+
96+
// CE only
97+
#[test]
98+
fn assert_decode_state_single_ce_brotli() {
99+
let case = Case {
100+
header_name: "Content-Encoding",
101+
expected_state: |s| matches!(s, DecodeState::ContentEncoding(_, _)),
102+
};
103+
run_case(&case, ContentEncoding::Brotli);
104+
}
105+
106+
#[test]
107+
fn assert_decode_state_single_ce_compress() {
108+
let case = Case {
109+
header_name: "Content-Encoding",
110+
expected_state: |s| matches!(s, DecodeState::ContentEncoding(_, _)),
111+
};
112+
run_case(&case, ContentEncoding::Compress);
113+
}
114+
115+
#[test]
116+
fn assert_decode_state_single_ce_deflate() {
117+
let case = Case {
118+
header_name: "Content-Encoding",
119+
expected_state: |s| matches!(s, DecodeState::ContentEncoding(_, _)),
120+
};
121+
run_case(&case, ContentEncoding::Deflate);
122+
}
123+
124+
#[test]
125+
fn assert_decode_state_single_ce_gzip() {
126+
let case = Case {
127+
header_name: "Content-Encoding",
128+
expected_state: |s| matches!(s, DecodeState::ContentEncoding(_, _)),
129+
};
130+
run_case(&case, ContentEncoding::Gzip);
131+
}
132+
133+
#[test]
134+
fn assert_decode_state_single_ce_identity() {
135+
let case = Case {
136+
header_name: "Content-Encoding",
137+
expected_state: |s| matches!(s, DecodeState::ContentEncoding(_, _)),
138+
};
139+
run_case(&case, ContentEncoding::Identity);
140+
}
141+
142+
#[test]
143+
fn assert_decode_state_single_ce_zstd() {
144+
let case = Case {
145+
header_name: "Content-Encoding",
146+
expected_state: |s| matches!(s, DecodeState::ContentEncoding(_, _)),
147+
};
148+
run_case(&case, ContentEncoding::Zstd);
149+
}

0 commit comments

Comments
 (0)