1
1
use assert_cmd:: prelude:: * ;
2
2
use predicates:: prelude:: * ;
3
+ use std:: path:: Path ;
3
4
use std:: process:: Command ;
4
- use tempfile:: TempDir ;
5
5
6
6
#[ test]
7
7
fn with_config_file ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
8
- let dir = TempDir :: new ( ) ?;
9
- std:: fs:: write (
10
- dir. path ( ) . join ( "app-config.yaml" ) ,
11
- "port: 8080\n database_url: \" postgres://localhost:5432/mydb\" " ,
12
- ) ?;
8
+ // path to basic example
9
+ let dir = Path :: new ( "examples/basic" ) ;
13
10
14
11
Command :: cargo_bin ( "basic" ) ?
15
- . current_dir ( dir. path ( ) )
12
+ . current_dir ( dir)
16
13
. assert ( )
17
14
. success ( )
15
+ . stdout ( predicate:: str:: contains ( "Final config:" ) )
18
16
. stdout ( predicate:: str:: contains ( "port: 8080" ) )
19
- . stdout ( predicate:: str:: contains (
20
- "database_url: \" postgres://localhost:5432/mydb\" " ,
21
- ) ) ;
17
+ . stdout ( predicate:: str:: contains ( "postgres://localhost:5432/mydb" ) )
18
+ . stdout ( predicate:: str:: contains ( "Loaded config from:" ) ) ;
22
19
23
20
Ok ( ( ) )
24
21
}
25
22
26
23
#[ test]
27
24
fn cli_override_port ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
28
- let dir = TempDir :: new ( ) ?;
29
- std:: fs:: write (
30
- dir. path ( ) . join ( "app-config.yaml" ) ,
31
- "port: 8080\n database_url: \" postgres://localhost:5432/mydb\" " ,
32
- ) ?;
25
+ // path to basic example
26
+ let dir = Path :: new ( "examples/basic" ) ;
33
27
34
28
Command :: cargo_bin ( "basic" ) ?
35
- . current_dir ( dir. path ( ) )
29
+ . current_dir ( dir)
36
30
. arg ( "--port" )
37
31
. arg ( "9090" )
38
32
. assert ( )
39
33
. success ( )
34
+ . stdout ( predicate:: str:: contains ( "Final config:" ) )
40
35
. stdout ( predicate:: str:: contains ( "port: 9090" ) )
41
- . stdout ( predicate:: str:: contains (
42
- "database_url: \" postgres://localhost:5432/mydb\" " ,
43
- ) ) ;
36
+ . stdout ( predicate:: str:: contains ( "postgres://localhost:5432/mydb" ) )
37
+ . stdout ( predicate:: str:: contains ( "Loaded config from:" ) ) ;
44
38
45
39
Ok ( ( ) )
46
40
}
@@ -51,8 +45,10 @@ fn no_config_uses_defaults() -> Result<(), Box<dyn std::error::Error>> {
51
45
. arg ( "--no-config" )
52
46
. assert ( )
53
47
. success ( )
48
+ . stdout ( predicate:: str:: contains ( "Final config:" ) )
54
49
. stdout ( predicate:: str:: contains ( "port: 8080" ) )
55
- . stdout ( predicate:: str:: contains ( "database_url: \" \" " ) ) ; // Default String is empty
50
+ . stdout ( predicate:: str:: contains ( "database_url: None" ) )
51
+ . stdout ( predicate:: str:: contains ( "No config file used" ) ) ;
56
52
57
53
Ok ( ( ) )
58
54
}
0 commit comments