File tree Expand file tree Collapse file tree 5 files changed +65
-0
lines changed Expand file tree Collapse file tree 5 files changed +65
-0
lines changed Original file line number Diff line number Diff line change @@ -20,3 +20,4 @@ futures-core-preview = "0.3.0-alpha.18"
20
20
21
21
[dev-dependencies ]
22
22
futures-util = " 0.3.0"
23
+ pretty_assertions = " 0.6.1"
Original file line number Diff line number Diff line change
1
+ use std:: { fs:: File , path:: PathBuf } ;
2
+
3
+ #[ macro_export]
4
+ macro_rules! assert {
5
+ ( $actual: expr, $expected: expr, $block: expr) => {
6
+ task:: block_on( async {
7
+ $block. await . unwrap( ) ;
8
+ pretty_assertions:: assert_eq!(
9
+ std:: str :: from_utf8( & $actual) . unwrap( ) ,
10
+ std:: str :: from_utf8( & $expected) . unwrap( )
11
+ ) ;
12
+ } )
13
+ } ;
14
+ }
15
+
16
+ pub fn read_fixture ( name : & str ) -> Vec < u8 > {
17
+ use std:: io:: Read ;
18
+
19
+ let directory: PathBuf = env ! ( "CARGO_MANIFEST_DIR" ) . into ( ) ;
20
+ let path: PathBuf = format ! ( "tests/fixtures/{}.txt" , name) . into ( ) ;
21
+ let mut file = File :: open ( directory. join ( path) ) . expect ( "Reading fixture file didn't work" ) ;
22
+ let mut contents = Vec :: new ( ) ;
23
+ file. read_to_end ( & mut contents)
24
+ . expect ( "Couldn't read fixture files contents" ) ;
25
+
26
+ let mut result = Vec :: < u8 > :: new ( ) ;
27
+ for byte in contents {
28
+ if byte == 0x0A {
29
+ result. push ( 0x0D ) ;
30
+ }
31
+ result. push ( byte) ;
32
+ }
33
+ result
34
+ }
Original file line number Diff line number Diff line change
1
+ POST / HTTP/1.1
2
+ Host: localhost:8080
3
+ User-Agent: curl/7.54.0
4
+ Accept: */*
5
+ Content-Length: 2
6
+ Content-Type: application/x-www-form-urlencoded
7
+
Original file line number Diff line number Diff line change
1
+ HTTP/1.1 200 OK
2
+ Content-Length: 0
3
+
Original file line number Diff line number Diff line change
1
+ mod common;
2
+ use async_h1:: { server, Body } ;
3
+ use async_std:: task;
4
+ use common:: read_fixture;
5
+ use http:: Response ;
6
+
7
+ #[ test]
8
+ fn test_basic_request ( ) {
9
+ let request = read_fixture ( "request1" ) ;
10
+ let expected = read_fixture ( "response1" ) ;
11
+ let mut actual = Vec :: new ( ) ;
12
+
13
+ assert ! (
14
+ actual,
15
+ expected,
16
+ server:: connect( & request[ ..] , & mut actual, |_req| {
17
+ async { Ok ( Response :: new( Body :: empty( "" . as_bytes( ) ) ) ) }
18
+ } )
19
+ ) ;
20
+ }
You can’t perform that action at this time.
0 commit comments