mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-08 01:05:47 +00:00
Start adding CLI tests
This commit is contained in:
@@ -5,3 +5,4 @@ mod beacon_node;
|
|||||||
mod boot_node;
|
mod boot_node;
|
||||||
mod exec;
|
mod exec;
|
||||||
mod validator_client;
|
mod validator_client;
|
||||||
|
mod validator_manager;
|
||||||
|
|||||||
63
lighthouse/tests/validator_manager.rs
Normal file
63
lighthouse/tests/validator_manager.rs
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
use serde::de::DeserializeOwned;
|
||||||
|
use std::fs;
|
||||||
|
use std::marker::PhantomData;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use std::process::Command;
|
||||||
|
use tempfile::{tempdir, TempDir};
|
||||||
|
use validator_manager::validators::create_validators::CreateConfig;
|
||||||
|
|
||||||
|
struct CommandLineTest<T> {
|
||||||
|
cmd: Command,
|
||||||
|
dir: TempDir,
|
||||||
|
config_path: PathBuf,
|
||||||
|
_phantom: PhantomData<T>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Default for CommandLineTest<T> {
|
||||||
|
fn default() -> Self {
|
||||||
|
let dir = tempdir().unwrap();
|
||||||
|
let config_path = dir.path().join("config.json");
|
||||||
|
let mut cmd = Command::new(env!("CARGO_BIN_EXE_lighthouse"));
|
||||||
|
cmd.arg("--dump_config")
|
||||||
|
.arg(format!("{:?}", config_path))
|
||||||
|
.arg("validator-manager");
|
||||||
|
Self {
|
||||||
|
cmd,
|
||||||
|
dir,
|
||||||
|
config_path,
|
||||||
|
_phantom: PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> CommandLineTest<T> {
|
||||||
|
fn flag(mut self, flag: &str, value: Option<&str>) -> Self {
|
||||||
|
self.cmd.arg(flag);
|
||||||
|
if let Some(value) = value {
|
||||||
|
self.cmd.arg(value);
|
||||||
|
}
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: DeserializeOwned> CommandLineTest<T> {
|
||||||
|
fn assert_success<F: Fn(T)>(mut self, func: F) {
|
||||||
|
let output = self.cmd.output().expect("should run command");
|
||||||
|
assert!(output.status.success(), "command should succeed");
|
||||||
|
|
||||||
|
let contents = fs::read_to_string(self.config_path).unwrap();
|
||||||
|
let config: T = serde_json::from_str(&contents).unwrap();
|
||||||
|
func(config)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CommandLineTest<CreateConfig> {
|
||||||
|
fn validator_create() -> Self {
|
||||||
|
Self::default().flag("validator", None).flag("create", None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
pub fn validator_create_defaults() {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ use std::path::PathBuf;
|
|||||||
use types::EthSpec;
|
use types::EthSpec;
|
||||||
use validators::create_validators::write_to_json_file;
|
use validators::create_validators::write_to_json_file;
|
||||||
|
|
||||||
mod validators;
|
pub mod validators;
|
||||||
|
|
||||||
pub const CMD: &str = "validator_manager";
|
pub const CMD: &str = "validator_manager";
|
||||||
|
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
|
|||||||
|
|
||||||
/// The CLI arguments are parsed into this struct before running the application. This step of
|
/// The CLI arguments are parsed into this struct before running the application. This step of
|
||||||
/// indirection allows for testing the underlying logic without needing to parse CLI arguments.
|
/// indirection allows for testing the underlying logic without needing to parse CLI arguments.
|
||||||
#[derive(Clone, Serialize, Deserialize)]
|
#[derive(Clone, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct CreateConfig {
|
pub struct CreateConfig {
|
||||||
pub output_path: PathBuf,
|
pub output_path: PathBuf,
|
||||||
pub first_index: u32,
|
pub first_index: u32,
|
||||||
|
|||||||
Reference in New Issue
Block a user