@@ -63,9 +63,21 @@ mod integration {
6363
6464 let n_http_port = find_free_port ( ) ;
6565 let n_https_port = find_free_port ( ) ;
66- let _nginx =
67- start_nginx ( n_http_port, n_https_port, format ! ( "0.0.0.0:{}" , relay_port) , nginx_cert)
68- . await ;
66+ let _nginx = match start_nginx (
67+ n_http_port,
68+ n_https_port,
69+ format ! ( "0.0.0.0:{}" , relay_port) ,
70+ nginx_cert,
71+ )
72+ . await
73+ {
74+ Ok ( nginx) => nginx,
75+ Err ( NginxInitError :: NginxNotAvailable ) => {
76+ eprintln ! ( "Skipping test: NGINX_EXE environment variable not set" ) ;
77+ return ;
78+ }
79+ Err ( e) => panic ! ( "Failed to start nginx: {}" , e) ,
80+ } ;
6981 tokio:: select! {
7082 _ = example_gateway_http( gateway_port) => {
7183 panic!( "Gateway is long running" ) ;
@@ -102,9 +114,21 @@ mod integration {
102114 } ) ;
103115 let n_http_port = find_free_port ( ) ;
104116 let n_https_port = find_free_port ( ) ;
105- let _nginx =
106- start_nginx ( n_http_port, n_https_port, format ! ( "unix:{}" , socket_path_str) , nginx_cert)
107- . await ?;
117+ let _nginx = match start_nginx (
118+ n_http_port,
119+ n_https_port,
120+ format ! ( "unix:{}" , socket_path_str) ,
121+ nginx_cert,
122+ )
123+ . await
124+ {
125+ Ok ( nginx) => nginx,
126+ Err ( NginxInitError :: NginxNotAvailable ) => {
127+ eprintln ! ( "Skipping test: NGINX_EXE environment variable not set" ) ;
128+ return Ok ( ( ) ) ;
129+ }
130+ Err ( e) => return Err ( Box :: new ( e) as Box < dyn std:: error:: Error > ) ,
131+ } ;
108132 tokio:: select! {
109133 _ = example_gateway_http( gateway_port) => {
110134 panic!( "Gateway is long running" ) ;
@@ -362,13 +386,21 @@ mod integration {
362386 } ) ;
363387 let n_http_port = find_free_port ( ) ;
364388 let n_https_port = find_free_port ( ) ;
365- let _nginx = start_nginx (
389+ let _nginx = match start_nginx (
366390 n_http_port,
367391 n_https_port,
368392 format ! ( "0.0.0.0:{}" , relay_port) ,
369393 nginx_cert,
370394 )
371- . await ;
395+ . await
396+ {
397+ Ok ( nginx) => nginx,
398+ Err ( NginxInitError :: NginxNotAvailable ) => {
399+ eprintln ! ( "Skipping test: NGINX_EXE environment variable not set" ) ;
400+ return ;
401+ }
402+ Err ( e) => panic ! ( "Failed to start nginx: {}" , e) ,
403+ } ;
372404 tokio:: select! {
373405 _ = example_gateway_https( gateway_port, gateway_cert) => {
374406 panic!( "Gateway is long running" ) ;
@@ -441,12 +473,13 @@ mod integration {
441473 struct NginxProcess {
442474 _child : tokio:: process:: Child ,
443475 config_path : PathBuf ,
476+ nginx_exe : PathBuf ,
444477 }
445478
446479 impl Drop for NginxProcess {
447480 fn drop ( & mut self ) {
448481 // NGINX spawns child processes. Gracefully shut them all down.
449- let _ = std:: process:: Command :: new ( "nginx" )
482+ let _ = std:: process:: Command :: new ( & self . nginx_exe )
450483 . arg ( "-s" )
451484 . arg ( "stop" )
452485 . arg ( "-c" )
@@ -455,14 +488,37 @@ mod integration {
455488 }
456489 }
457490
491+ #[ derive( Debug ) ]
492+ enum NginxInitError {
493+ NginxNotAvailable ,
494+ UnknownError ( Box < dyn std:: error:: Error > ) ,
495+ }
496+
497+ impl std:: fmt:: Display for NginxInitError {
498+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
499+ match self {
500+ NginxInitError :: NginxNotAvailable =>
501+ write ! ( f, "NGINX_EXE environment variable not set - skipping nginx tests" ) ,
502+ NginxInitError :: UnknownError ( e) => write ! ( f, "Unknown error: {}" , e) ,
503+ }
504+ }
505+ }
506+
507+ impl std:: error:: Error for NginxInitError { }
508+
458509 async fn start_nginx (
459510 n_http_port : u16 ,
460511 n_https_port : u16 ,
461512 proxy_pass : String ,
462513 cert : Certificate ,
463- ) -> Result < NginxProcess , Box < dyn std :: error :: Error > > {
514+ ) -> Result < NginxProcess , NginxInitError > {
464515 use std:: io:: Write ;
465516
517+ // Check for NGINX_EXE environment variable
518+ let nginx_exe = std:: env:: var ( "NGINX_EXE" )
519+ . map ( PathBuf :: from)
520+ . map_err ( |_| NginxInitError :: NginxNotAvailable ) ?;
521+
466522 let temp_dir = std:: env:: var ( "TMPDIR" ) . unwrap_or_else ( |_| "/tmp" . into ( ) ) ; // Use Nix's TMPDIR
467523 let unique_suffix = uuid:: Uuid :: new_v4 ( ) . to_string ( ) ; // Ensures uniqueness
468524
@@ -498,7 +554,7 @@ mod integration {
498554 NamedTempFile :: new ( ) . expect ( "Failed to create temp file for nginx config" ) ;
499555 writeln ! ( config_file, "{}" , nginx_conf) . expect ( "Failed to write nginx config" ) ;
500556 let config_path = config_file. path ( ) . to_path_buf ( ) ;
501- let _child = Command :: new ( "nginx" )
557+ let _child = Command :: new ( & nginx_exe )
502558 . arg ( "-c" )
503559 . arg ( config_path. as_os_str ( ) )
504560 . spawn ( )
@@ -512,14 +568,14 @@ mod integration {
512568 Err ( _) if start_time. elapsed ( ) < timeout => {
513569 tokio:: time:: sleep ( std:: time:: Duration :: from_millis ( 100 ) ) . await ;
514570 }
515- Err ( e) => return Err ( Box :: new ( e) ) ,
571+ Err ( e) => return Err ( NginxInitError :: UnknownError ( Box :: new ( e) ) ) ,
516572 }
517573 }
518574
519575 // Keep the config file open as long as NGINX is using it
520576 std:: mem:: forget ( config_file) ;
521577
522- Ok ( NginxProcess { _child, config_path } )
578+ Ok ( NginxProcess { _child, config_path, nginx_exe } )
523579 }
524580
525581 fn full < T : Into < Bytes > > ( chunk : T ) -> BoxBody < Bytes , hyper:: Error > {
0 commit comments