mod common;
use common::TestWashInstance;
use std::collections::HashMap;
use wash_cli::cmd::config::ConfigCliCommand;
use wash_lib::cli::{CliConnectionOpts, OutputKind};
#[tokio::test]
async fn test_config_put_and_get() -> anyhow::Result<()> {
let wash_instance = TestWashInstance::create().await?;
let config_values = vec!["key=value".to_string(), "key2=value2".to_string()];
let command = ConfigCliCommand::PutCommand {
opts: CliConnectionOpts {
ctl_port: Some(wash_instance.nats_port.to_string()),
..Default::default()
},
name: "foobar".to_string(),
config_values,
};
wash_cli::cmd::config::handle_command(command, OutputKind::Json).await?;
let retrieved_config: HashMap<String, serde_json::Value> =
wash_cli::cmd::config::handle_command(
ConfigCliCommand::GetCommand {
opts: CliConnectionOpts {
ctl_port: Some(wash_instance.nats_port.to_string()),
..Default::default()
},
name: "foobar".to_string(),
},
OutputKind::Json,
)
.await?
.map;
assert_eq!(retrieved_config.len(), 2);
assert_eq!(retrieved_config.get("key").unwrap(), "value");
assert_eq!(retrieved_config.get("key2").unwrap(), "value2");
Ok(())
}
#[tokio::test]
async fn test_config_secret_name_error() -> anyhow::Result<()> {
let config_values = vec!["key=value".to_string()];
let command = ConfigCliCommand::PutCommand {
opts: CliConnectionOpts::default(),
name: "SECRET_foo".to_string(),
config_values,
};
let result = wash_cli::cmd::config::handle_command(command, OutputKind::Json).await;
assert!(result.is_err());
Ok(())
}