File tree Expand file tree Collapse file tree 4 files changed +46
-26
lines changed
Expand file tree Collapse file tree 4 files changed +46
-26
lines changed Original file line number Diff line number Diff line change @@ -3,5 +3,12 @@ name = "bibimbap-backend"
33version = " 0.1.0"
44edition = " 2021"
55
6+ [lib ]
7+ path = " src/lib.rs"
8+
9+ [[bin ]]
10+ path = " src/main.rs"
11+ name = " bibimbap-backend"
12+
613[dependencies ]
714rocket = " 0.5.1"
Original file line number Diff line number Diff line change 1+ #[ macro_use]
2+ extern crate rocket;
3+
4+ use rocket:: { Build , Rocket } ;
5+
6+ #[ get( "/health_check" ) ]
7+ fn health_check ( ) {
8+ ( )
9+ }
10+
11+ pub fn run ( ) -> Rocket < Build > {
12+ rocket:: build ( ) . mount ( "/" , routes ! [ health_check] )
13+ }
Original file line number Diff line number Diff line change 1- #[ macro_use]
2- extern crate rocket;
1+ use bibimbap_backend:: run;
32
4- #[ get( "/health_check" ) ]
5- fn health_check ( ) {
6- ( )
7- }
8-
9- #[ launch]
10- fn rocket ( ) -> _ {
11- rocket:: build ( ) . mount ( "/" , routes ! [ health_check] )
12- }
13-
14- #[ cfg( test) ]
15- mod test {
16- use super :: rocket;
17- use rocket:: http:: Status ;
18- use rocket:: local:: blocking:: Client ;
19- use std:: io:: Read ;
20-
21- #[ test]
22- fn health_check_works ( ) {
23- let client = Client :: tracked ( rocket ( ) ) . expect ( "Failed to create client" ) ;
24- let response = client. get ( uri ! ( super :: health_check) ) . dispatch ( ) ;
25-
26- assert_eq ! ( response. status( ) , Status :: Ok ) ;
27- assert_eq ! ( response. bytes( ) . count( ) , 0 ) ;
3+ #[ rocket:: main]
4+ async fn main ( ) {
5+ if let Err ( e) = run ( ) . launch ( ) . await {
6+ println ! ( "Failed to launch Rocket: {e}" ) ;
7+ drop ( e) ;
288 }
299}
Original file line number Diff line number Diff line change 1+ #[ macro_use]
2+ extern crate rocket;
3+
4+ use rocket:: http:: Status ;
5+ use rocket:: local:: blocking:: Client ;
6+ use rocket:: { Build , Rocket } ;
7+ use std:: io:: Read ;
8+
9+ fn spawn_app ( ) -> Rocket < Build > {
10+ bibimbap_backend:: run ( )
11+ }
12+
13+ #[ test]
14+ fn health_check_works ( ) {
15+ let client = Client :: tracked ( spawn_app ( ) ) . expect ( "Failed to create client" ) ;
16+ let response = client. get ( uri ! ( "/health_check" ) ) . dispatch ( ) ;
17+
18+ assert_eq ! ( response. status( ) , Status :: Ok ) ;
19+ assert_eq ! ( response. bytes( ) . count( ) , 0 ) ;
20+ }
You can’t perform that action at this time.
0 commit comments