add test_save for install config (#28397)

This commit is contained in:
Yihau Chen 2022-10-20 17:34:08 +08:00 committed by GitHub
parent 2c0831aa12
commit a1b03ec1b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 78 additions and 0 deletions

1
Cargo.lock generated
View File

@ -5396,6 +5396,7 @@ dependencies = [
"lazy_static",
"nix",
"reqwest",
"scopeguard",
"semver 1.0.14",
"serde",
"serde_yaml 0.9.13",

View File

@ -23,6 +23,7 @@ indicatif = "0.17.1"
lazy_static = "1.4.0"
nix = "0.25.0"
reqwest = { version = "0.11.12", default-features = false, features = ["blocking", "brotli", "deflate", "gzip", "rustls-tls", "json"] }
scopeguard = "1.1.0"
semver = "1.0.14"
serde = { version = "1.0.144", features = ["derive"] }
serde_yaml = "0.9.13"

View File

@ -86,3 +86,79 @@ impl Config {
self.releases_dir.join(release_id)
}
}
#[cfg(test)]
mod test {
use {
super::*,
scopeguard::defer,
std::{
env,
fs::{read_to_string, remove_file},
},
};
#[test]
fn test_save() {
let root_dir = env::var("CARGO_MANIFEST_DIR").expect("$CARGO_MANIFEST_DIR");
let json_rpc_url = "https://api.mainnet-beta.solana.com";
let pubkey = Pubkey::default();
let config_name = "config.yaml";
let config_path = format!("{}/{}", root_dir, config_name);
let config = Config::new(&root_dir, json_rpc_url, &pubkey, None);
assert_eq!(config.save(config_name), Ok(()));
defer! {
remove_file(&config_path).unwrap();
}
assert_eq!(
read_to_string(&config_path).unwrap(),
format!(
"---
json_rpc_url: https://api.mainnet-beta.solana.com
update_manifest_pubkey:
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
current_update_manifest: null
update_poll_secs: 3600
explicit_release: null
releases_dir: {}/releases
active_release_dir: {}/active_release
",
root_dir, root_dir
),
);
}
}