@@ -2,7 +2,7 @@ use std::collections::BTreeMap;
22use std:: error:: Error as StdError ;
33use std:: env;
44use std:: fmt;
5- use std:: fs:: { self , File } ;
5+ use std:: fs:: File ;
66use std:: io:: Read ;
77use std:: path:: Path ;
88use std:: u16;
@@ -147,9 +147,6 @@ impl ServerConfig {
147147 Some ( dir) => dir,
148148 } ;
149149 let checkout_root = Path :: new ( & checkout_root_string) ;
150- if let Err ( _) = fs:: create_dir_all ( & checkout_root) {
151- return Err ( Error :: DirectoryCreateError ) ;
152- }
153150 match VerifiedPath :: directory ( None , checkout_root) {
154151 Ok ( v) => v,
155152 Err ( _) => return Err ( Error :: InvalidCheckoutRoot ) ,
@@ -169,9 +166,6 @@ impl ServerConfig {
169166 Some ( dir) => dir,
170167 } ;
171168 let log_root = Path :: new ( & log_root_string) ;
172- if let Err ( _) = fs:: create_dir_all ( & log_root) {
173- return Err ( Error :: DirectoryCreateError ) ;
174- }
175169 match VerifiedPath :: directory ( None , log_root) {
176170 Ok ( v) => v,
177171 Err ( _) => return Err ( Error :: InvalidLogRoot ) ,
@@ -272,6 +266,7 @@ mod tests {
272266 use super :: * ;
273267 use std:: path:: Path ;
274268 use std:: env;
269+ use std:: fs;
275270
276271 macro_rules! expect_error {
277272 ( $i: ident, $error: path ) => { {
@@ -336,59 +331,62 @@ mod tests {
336331 }
337332
338333 #[ test]
339- fn test_invalid_config_missing_checkout_root ( ) {
340- env:: set_var ( "XDG_DATA_HOME" , "/tmp" ) ;
334+ fn test_invalid_config_bad_secret ( ) {
341335 let toml = r#"
342336 [config]
343- secret = "it's a secret to everyone"
337+ secret = {}
344338 port = 5712
345339 hostname = "127.0.0.1"
340+ checkout_root = "/tmp"
346341 log_root = "/tmp"
347342 "# ;
348- let config = ServerConfig :: from ( & toml) . unwrap ( ) ;
349- assert_eq ! ( config. checkout_root. path( ) , Path :: new( "/tmp/hookshot/checkouts" ) ) ;
343+ expect_error ! ( toml, Error :: InvalidSecret ) ;
350344 }
351345
352346 #[ test]
353- fn test_invalid_config_bad_secret ( ) {
347+ fn test_invalid_config_missing_secret ( ) {
354348 let toml = r#"
355349 [config]
356- secret = {}
357350 port = 5712
358351 hostname = "127.0.0.1"
359352 checkout_root = "/tmp"
360353 log_root = "/tmp"
361354 "# ;
362- expect_error ! ( toml, Error :: InvalidSecret ) ;
355+ expect_error ! ( toml, Error :: MissingSecret ) ;
363356 }
364357
365358 #[ test]
366- fn test_invalid_config_missing_secret ( ) {
359+ fn test_config_default_checkout_root ( ) {
360+ env:: set_var ( "XDG_DATA_HOME" , "tmp" ) ;
367361 let toml = r#"
368362 [config]
363+ secret = "it's a secret to everyone"
369364 port = 5712
370365 hostname = "127.0.0.1"
371- checkout_root = "/tmp"
372366 log_root = "/tmp"
373367 "# ;
374- expect_error ! ( toml, Error :: MissingSecret ) ;
368+ let checkout_path = Path :: new ( "tmp/hookshot/checkouts" ) ;
369+ fs:: create_dir_all ( & checkout_path) . unwrap ( ) ;
370+ let config = ServerConfig :: from ( & toml) . unwrap ( ) ;
371+ assert_eq ! ( config. checkout_root. path( ) , checkout_path) ;
375372 }
376373
377374 #[ test]
378375 fn test_config_default_log_root ( ) {
379- env:: set_var ( "XDG_DATA_HOME" , "/ tmp" ) ;
376+ env:: set_var ( "XDG_DATA_HOME" , "tmp" ) ;
380377 let toml = r#"
381378 [config]
382379 port = 5712
383380 hostname = "127.0.0.1"
384381 secret = "shh"
385382 checkout_root = "/tmp"
386383 "# ;
384+ let log_path = Path :: new ( "tmp/hookshot/logs" ) ;
385+ fs:: create_dir_all ( & log_path) . unwrap ( ) ;
387386 let config = ServerConfig :: from ( & toml) . unwrap ( ) ;
388- assert_eq ! ( config. log_root. path( ) , Path :: new ( "/tmp/hookshot/logs" ) ) ;
387+ assert_eq ! ( config. log_root. path( ) , log_path ) ;
389388 }
390389
391-
392390 #[ test]
393391 fn test_invalid_config_invalid_log_root ( ) {
394392 let toml = r#"
0 commit comments