Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

components test: add settings-file #262

Merged
merged 1 commit into from
Mar 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions crates/cli/src/commands/components/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ pub struct Options {
#[arg(long="settings", value_parser = parse_settings)]
pub settings: Option<HashMap<String, String>>,

/// File containing the settings
#[arg(long = "settings-file")]
pub settings_file: Option<String>,

/// The event type you want to test
#[arg(long = "event-type", value_parser = ["page", "track", "user"])]
pub event_type: Option<String>,
Expand Down Expand Up @@ -123,9 +127,30 @@ async fn test_data_collection_component(opts: Options) -> anyhow::Result<()> {
let mut settings_map = HashMap::new();

// insert user provided settings
if let Some(parsed_settings) = opts.settings {
for (key, value) in parsed_settings {
settings_map.insert(key, value);
match (opts.settings, opts.settings_file) {
(Some(_), Some(_)) => {
return Err(anyhow::anyhow!(
"Please provide either settings or settings-file, not both"
));
}
(None, None) => {}
(Some(settings), None) => {
for (key, value) in settings {
settings_map.insert(key, value);
}
}
(None, Some(settings_file)) => {
#[derive(serde::Deserialize)]
struct Settings {
settings: HashMap<String, String>,
}

let settings_file = std::fs::read_to_string(settings_file)?;
let config: Settings = toml::from_str(&settings_file).expect("Failed to parse TOML");

for (key, value) in config.settings {
settings_map.insert(key, value);
}
}
}

Expand Down