pub fn new() -> Result<Self, Box<dyn Error>> {
        // Create the store directory.
        let tempdir = TempDir::new()?;

        // Spawn the cockroach subprocess.
        let url_file = tempdir.path().join("url");

        let process = Command::new("cockroach")
            .arg("start")
            .arg("--insecure")
            .arg("--listen-addr=localhost")
            .arg("--port=0")
            .arg("--http-port=0")
            .arg(format!("--listening-url-file={}", url_file.display()))
            .arg(format!("--store={}", tempdir.path().display()))
            .spawn()
            .map_err(|e| format!("Failed to start cockroach: {}. Did you remember to install it? See https://www.cockroachlabs.com/docs/stable/install-cockroachdb.html for installation instructions.", e.description()))?;

        // Wait for the URL file to be written.
        let mut url: String;
        loop {
            if url_file.exists() {
                match std::fs::read_to_string(url_file.clone()) {
                    Ok(s) => {
                        // Cockroach doesn't write the URL file atomically, so
                        // we look for the trailing newline to tell when it's
                        // complete.
                        if s.contains("\n") {
                            url = s.trim().to_string();
                            break;
                        }
                    }
                    Err(_) => {}
                };
            }
            std::thread::sleep(Duration::from_millis(10));
        }

        // Create test database.
        let conn = Connection::connect(url.clone(), TlsMode::None)?;
        conn.execute("CREATE DATABASE test", &[])?;
        url = url.replace("?sslmode=disable", "/test?sslmode=disable");

        Result::Ok(TempCockroach {
            tempdir: tempdir,
            process: process,
            url: url,
        })
    }
/// Create a new temporary CockroachDB instance.
Create a new temporary CockroachDB instance.
Create a new temporary CockroachDB instance .
pub fn new() -> Result<Self, Box<dyn Error>> {
        // Create the store directory.
        let tempdir = TempDir::new()?;
        // Spawn the cockroach subprocess.
        let url_file = tempdir.path().join("url");
        let process = Command::new("cockroach")
            .arg("start")
            .arg("--insecure")
            .arg("--listen-addr=localhost")
            .arg("--port=0")
            .arg("--http-port=0")
            .arg(format!("--listening-url-file={}", url_file.display()))
            .arg(format!("--store={}", tempdir.path().display()))
            .spawn()
            .map_err(|e| format!("Failed to start cockroach: {}. Did you remember to install it? See https://www.cockroachlabs.com/docs/stable/install-cockroachdb.html for installation instructions.", e.description()))?;
        // Wait for the URL file to be written.
        let mut url: String;
        loop {
            if url_file.exists() {
                match std::fs::read_to_string(url_file.clone()) {
                    Ok(s) => {
                        // Cockroach doesn't write the URL file atomically, so
                        // we look for the trailing newline to tell when it's
                        // complete.
                        if s.contains("\n") {
                            url = s.trim().to_string();
                            break;
                        }
                    }
                    Err(_) => {}
                };
            }
            std::thread::sleep(Duration::from_millis(10));
        }
        // Create test database.
        let conn = Connection::connect(url.clone(), TlsMode::None)?;
        conn.execute("CREATE DATABASE test", &[])?;
        url = url.replace("?sslmode=disable", "/test?sslmode=disable");
        Result::Ok(TempCockroach {
            tempdir: tempdir,
            process: process,
            url: url,
        })
    }
pub fn new ( ) -> Result < Self , Box < dyn Error > > { // Create the store directory. let tempdir = TempDir :: new ( ) ? ; // Spawn the cockroach subprocess. let url_file = tempdir . path ( ) . join ( " " ) ; let process = Command :: new ( " " ) . arg ( " " ) . arg ( " " ) . arg ( " " ) . arg ( " " ) . arg ( " " ) . arg ( format ! ( " " url_file display ( ) ) ) . arg ( format ! ( " " tempdir path ( ) display ( ) ) ) . spawn ( ) . map_err ( | e | format ! ( " " e description ( ) ) ) ? ; // Wait for the URL file to be written. let mut url : String ; loop { if url_file . exists ( ) { match std :: fs :: read_to_string ( url_file . clone ( ) ) { Ok ( s ) => { // Cockroach doesn't write the URL file atomically, so // we look for the trailing newline to tell when it's // complete. if s . contains ( " \n " ) { url = s . trim ( ) . to_string ( ) ; break ; } } Err ( _ ) => { } } ; } std :: thread :: sleep ( Duration :: from_millis ( 10 ) ) ; } // Create test database. let conn = Connection :: connect ( url . clone ( ) , TlsMode :: None ) ? ; conn . execute ( " " , & [ ] ) ? ; url = url . replace ( " " , " " ) ; Result :: Ok ( TempCockroach { tempdir : tempdir , process : process , url : url , } ) }
Create a new temporary CockroachDB instance.
Create a new temporary CockroachDB instance .