use super::*; #[test] fn default() { CommandBuilder::new("settings") .integration_test(false) .stdout_regex( r#"\{ "bitcoin_data_dir": ".*(Bitcoin|bitcoin)", "bitcoin_rpc_limit": 12, "bitcoin_rpc_password": null, "bitcoin_rpc_url": "127.0.0.1:8332", "bitcoin_rpc_username": null, "chain": "mainnet", "commit_interval": 5000, "config": null, "config_dir": null, "cookie_file": ".*\.cookie", "data_dir": ".*", "first_rune_height": 855000, "height_limit": null, "http_port": null, "index": ".*index\.redb", "index_addresses": false, "index_cache_size": \d+, "index_transactions": false, "integration_test": false, "server_password": null, "server_url": null, "server_username": null \} "#, ) .run_and_extract_stdout(); } #[test] fn config_is_loaded_from_config_option() { let tempdir = TempDir::new().unwrap(); let config = tempdir.path().join("bitomc.yaml"); fs::write(&config, "chain: regtest").unwrap(); CommandBuilder::new(format!("--config {} settings", config.to_str().unwrap())) .stdout_regex( r#".* "chain": "regtest", .*"#, ) .run_and_extract_stdout(); } #[test] fn config_invalid_error_message() { let tempdir = TempDir::new().unwrap(); let config = tempdir.path().join("bitomc.yaml"); fs::write(&config, "foo").unwrap(); CommandBuilder::new(format!("--config {} settings", config.to_str().unwrap())) .stderr_regex("error: failed to deserialize config file `.*bitomc.yaml`\nbecause:.*") .expected_exit_code(1) .run_and_extract_stdout(); } #[test] fn config_not_found_error_message() { let tempdir = TempDir::new().unwrap(); let config = tempdir.path().join("bitomc.yaml"); CommandBuilder::new(format!("--config {} settings", config.to_str().unwrap())) .stderr_regex("error: failed to open config file `.*bitomc.yaml`\nbecause:.*") .expected_exit_code(1) .run_and_extract_stdout(); } #[test] fn config_is_loaded_from_config_dir() { let tempdir = TempDir::new().unwrap(); fs::write(tempdir.path().join("bitomc.yaml"), "chain: regtest").unwrap(); CommandBuilder::new(format!( "--config-dir {} settings", tempdir.path().to_str().unwrap() )) .stdout_regex( r#".* "chain": "regtest", .*"#, ) .run_and_extract_stdout(); } #[test] fn config_is_loaded_from_data_dir() { CommandBuilder::new("settings") .write("bitomc.yaml", "chain: regtest") .stdout_regex( r#".* "chain": "regtest", .*"#, ) .run_and_extract_stdout(); } #[test] fn env_is_loaded() { CommandBuilder::new("settings") .stdout_regex( r#".* "chain": "mainnet", .*"#, ) .run_and_extract_stdout(); CommandBuilder::new("settings") .env("BITOMC_CHAIN", "regtest") .stdout_regex( r#".* "chain": "regtest", .*"#, ) .run_and_extract_stdout(); } #[cfg(unix)] #[test] fn invalid_env_error_message() { use std::os::unix::ffi::OsStringExt; CommandBuilder::new("settings") .env("BITOMC_BAR", OsString::from_vec(b"\xFF".into())) .stderr_regex("error: environment variable `BITOMC_BAR` not valid unicode: `�`\n") .expected_exit_code(1) .run_and_extract_stdout(); }