Skip to content

Commit

Permalink
test: add a test for writing the generated config file + key
Browse files Browse the repository at this point in the history
  • Loading branch information
QuinnWilton committed Mar 6, 2024
1 parent 3e84253 commit 50a2543
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions homestar-runtime/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{
};
use anyhow::Result;
use assert_cmd::prelude::*;
use homestar_runtime::Settings;
use once_cell::sync::Lazy;
use predicates::prelude::*;
use std::{
Expand Down Expand Up @@ -400,3 +401,39 @@ fn test_init_interactive_no_tty() -> Result<()> {

Ok(())
}

#[test]
#[serial_test::parallel]
fn test_init_writes_config() -> Result<()> {
let uuid = uuid::Uuid::new_v4();
let config_name = format!("tests/fixtures/{}_config.toml", uuid);
let key_name = format!("tests/fixtures/{}_key.pem", uuid);

Command::new(BIN.as_os_str())
.arg("init")
.arg("--output")
.arg(config_name.clone())
.arg("--no-input")
.arg("--key-type")
.arg("ed25519")
.arg("--key-file")
.arg(key_name.clone())
.assert()
.success()
.stdout(predicate::str::contains(format!(
"Writing settings to \"{}\"",
config_name.clone()
)));

let config = Settings::load_from_file(config_name.clone().into());
let secret_key =
ed25519_compact::SecretKey::from_pem(&std::fs::read_to_string(key_name.clone()).unwrap());

std::fs::remove_file(config_name).unwrap();
std::fs::remove_file(key_name).unwrap();

assert!(config.is_ok());
assert!(secret_key.is_ok());

Ok(())
}

0 comments on commit 50a2543

Please sign in to comment.