@@ -52,27 +52,40 @@ impl Handler for Static {
52
52
#[ cfg( test) ]
53
53
mod tests {
54
54
extern crate test = "conduit-test" ;
55
+
56
+ use std:: io:: { fs, File , TempDir , UserRWX } ;
57
+
55
58
use conduit;
56
59
use conduit:: Handler ;
57
60
use Static ;
58
61
59
62
#[ test]
60
63
fn test_static ( ) {
61
- let root = Path :: new ( file ! ( ) ) . dir_path ( ) . dir_path ( ) ;
62
- let handler = Static :: new ( root) ;
64
+ let td = TempDir :: new ( "conduit-static" ) . unwrap ( ) ;
65
+ let root = td. path ( ) ;
66
+ let handler = Static :: new ( root. clone ( ) ) ;
67
+ File :: create ( & root. join ( "Cargo.toml" ) ) . write ( b"[package]" ) . unwrap ( ) ;
63
68
let mut req = test:: MockRequest :: new ( conduit:: Get , "/Cargo.toml" ) ;
64
69
let mut res = handler. call ( & mut req) . ok ( ) . expect ( "No response" ) ;
65
70
let body = res. body . read_to_str ( ) . ok ( ) . expect ( "No body" ) ;
66
- assert ! ( body. as_slice( ) . contains( "[package]" ) , "The Cargo.toml was provided" ) ;
67
- assert_eq ! ( res. headers. find_equiv( & "Content-Type" ) . expect( "No content-type" ) , & vec!( "text/plain" . to_str( ) ) ) ;
71
+ assert_eq ! ( body. as_slice( ) , "[package]" ) ;
72
+ assert_eq ! ( res. headers. find_equiv( & "Content-Type" )
73
+ . expect( "No content-type" ) ,
74
+ & vec!( "text/plain" . to_str( ) ) ) ;
68
75
}
69
76
70
77
#[ test]
71
78
fn test_mime_types ( ) {
72
- let root = Path :: new ( file ! ( ) ) . dir_path ( ) . dir_path ( ) ;
73
- let handler = Static :: new ( root) ;
79
+ let td = TempDir :: new ( "conduit-static" ) . unwrap ( ) ;
80
+ let root = td. path ( ) ;
81
+ fs:: mkdir ( & root. join ( "src" ) , UserRWX ) . unwrap ( ) ;
82
+ File :: create ( & root. join ( "src/fixture.css" ) ) . unwrap ( ) ;
83
+
84
+ let handler = Static :: new ( root. clone ( ) ) ;
74
85
let mut req = test:: MockRequest :: new ( conduit:: Get , "/src/fixture.css" ) ;
75
86
let res = handler. call ( & mut req) . ok ( ) . expect ( "No response" ) ;
76
- assert_eq ! ( res. headers. find_equiv( & "Content-Type" ) . expect( "No content-type" ) , & vec!( "text/css" . to_str( ) ) ) ;
87
+ assert_eq ! ( res. headers. find_equiv( & "Content-Type" )
88
+ . expect( "No content-type" ) ,
89
+ & vec!( "text/css" . to_str( ) ) ) ;
77
90
}
78
91
}
0 commit comments