fn new() -> Self {
        // Initialize logger
        LOGGER_INIT.call_once(|| {
            if env::var("RUST_LOG")
                .unwrap_or_else(|_| "".into())
                .is_empty()
            {
                env::set_var("RUST_LOG", "sekursranko=error");
            }
            env_logger::init();
        });

        // Create backup tmpdir
        let backup_dir = tempfile::Builder::new()
            .prefix("sekursranko-test")
            .tempdir()
            .expect("Could not create temporary backup directory");

        // Create config object
        let config = ServerConfig {
            max_backup_bytes: 524_288,
            retention_days: 180,
            backup_dir: backup_dir.path().to_path_buf(),
            listen_on: "-integrationtest-".to_string(),
        };

        // Run server
        let addr = ([127, 0, 0, 1], 0).into();
        let service = MakeBackupService::new(config.clone());
        let (port_tx, port_rx) = std::sync::mpsc::channel();
        let handle = thread::spawn(move || {
            let rt = tokio::runtime::Runtime::new().unwrap();
            rt.block_on(async move {
                let server = Server::bind(&addr).serve(service);
                let port = server.local_addr().port();

                // Using port 0 when binding, we can know the final port only
                // once the server starts. Therefore, we use a channel to send
                // the final port outside this thread.
                port_tx.send(port).unwrap();

                // Run server until completion
                if let Err(e) = server.await {
                    eprintln!("Server error: {}", e);
                    std::process::exit(1);
                };
            });
        });
        let port = port_rx.recv().unwrap();
        let base_url = format!("http://127.0.0.1:{}", port);

        TestServer {
            _handle: handle,
            base_url,
            backup_dir,
            config,
        }
    }
/// Create a new test server instance.
Create a new test server instance.
Create a new test server instance .
fn new() -> Self {
        // Initialize logger
        LOGGER_INIT.call_once(|| {
            if env::var("RUST_LOG")
                .unwrap_or_else(|_| "".into())
                .is_empty()
            {
                env::set_var("RUST_LOG", "sekursranko=error");
            }
            env_logger::init();
        });
        // Create backup tmpdir
        let backup_dir = tempfile::Builder::new()
            .prefix("sekursranko-test")
            .tempdir()
            .expect("Could not create temporary backup directory");
        // Create config object
        let config = ServerConfig {
            max_backup_bytes: 524_288,
            retention_days: 180,
            backup_dir: backup_dir.path().to_path_buf(),
            listen_on: "-integrationtest-".to_string(),
        };
        // Run server
        let addr = ([127, 0, 0, 1], 0).into();
        let service = MakeBackupService::new(config.clone());
        let (port_tx, port_rx) = std::sync::mpsc::channel();
        let handle = thread::spawn(move || {
            let rt = tokio::runtime::Runtime::new().unwrap();
            rt.block_on(async move {
                let server = Server::bind(&addr).serve(service);
                let port = server.local_addr().port();
                // Using port 0 when binding, we can know the final port only
                // once the server starts. Therefore, we use a channel to send
                // the final port outside this thread.
                port_tx.send(port).unwrap();
                // Run server until completion
                if let Err(e) = server.await {
                    eprintln!("Server error: {}", e);
                    std::process::exit(1);
                };
            });
        });
        let port = port_rx.recv().unwrap();
        let base_url = format!("http://127.0.0.1:{}", port);
        TestServer {
            _handle: handle,
            base_url,
            backup_dir,
            config,
        }
    }
fn new ( ) -> Self { // Initialize logger LOGGER_INIT . call_once ( | | { if env :: var ( " " ) . unwrap_or_else ( | _ | " " . into ( ) ) . is_empty ( ) { env :: set_var ( " " , " " ) ; } env_logger :: init ( ) ; } ) ; // Create backup tmpdir let backup_dir = tempfile :: Builder :: new ( ) . prefix ( " " ) . tempdir ( ) . expect ( " " ) ; // Create config object let config = ServerConfig { max_backup_bytes : 524_288 , retention_days : 180 , backup_dir : backup_dir . path ( ) . to_path_buf ( ) , listen_on : " " . to_string ( ) , } ; // Run server let addr = ( [ 127 , 0 , 0 , 1 ] , 0 ) . into ( ) ; let service = MakeBackupService :: new ( config . clone ( ) ) ; let ( port_tx , port_rx ) = std :: sync :: mpsc :: channel ( ) ; let handle = thread :: spawn ( move | | { let rt = tokio :: runtime :: Runtime :: new ( ) . unwrap ( ) ; rt . block_on ( async move { let server = Server :: bind ( & addr ) . serve ( service ) ; let port = server . local_addr ( ) . port ( ) ; // Using port 0 when binding, we can know the final port only // once the server starts. Therefore, we use a channel to send // the final port outside this thread. port_tx . send ( port ) . unwrap ( ) ; // Run server until completion if let Err ( e ) = server . await { eprintln ! ( " " e ) ; std :: process :: exit ( 1 ) ; } ; } ) ; } ) ; let port = port_rx . recv ( ) . unwrap ( ) ; let base_url = format ! ( " " port ) ; TestServer { _handle : handle , base_url , backup_dir , config , } }
Create a new test server instance.
Create a new test server instance .