summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorSebastian Holmin <sebastian.holmin@mullvad.net>2025-01-16 15:41:45 +0100
committerSebastian Holmin <sebastian.holmin@mullvad.net>2025-01-22 13:32:15 +0100
commitb198ecd495f75117c482eea2f9d8cd738ad14441 (patch)
tree66ffb72550e367f13fe4b68881937627d79a390f /test
parentcd5cc1a09b18c8f1a878c4652e93b069ff0369d3 (diff)
downloadmullvadvpn-b198ecd495f75117c482eea2f9d8cd738ad14441.tar.xz
mullvadvpn-b198ecd495f75117c482eea2f9d8cd738ad14441.zip
Add `config` subcommand to `test-manager`
Move vm subcommand into config subcommand Also change the `test-manager config vm list` command to just list configured VMs, instead of their configuration contents.
Diffstat (limited to 'test')
-rwxr-xr-xtest/test-by-version.sh2
-rw-r--r--test/test-manager/src/config/io.rs2
-rw-r--r--test/test-manager/src/main.rs128
3 files changed, 84 insertions, 48 deletions
diff --git a/test/test-by-version.sh b/test/test-by-version.sh
index ef7b2e5ab4..f409a214cc 100755
--- a/test/test-by-version.sh
+++ b/test/test-by-version.sh
@@ -7,7 +7,7 @@ usage() {
echo
echo "Required environment variables:"
echo " - ACCOUNT_TOKEN: Valid MullvadVPN account number"
- echo " - TEST_OS: Name of the VM configuration to use. List available configurations with 'cargo run --bin test-manager list'"
+ echo " - TEST_OS: Name of the VM configuration to use. List available configurations with 'cargo run --bin test-manager config vm list'"
echo "Optional environment variables:"
echo " - APP_VERSION: The version of the app to test (defaults to the latest stable release)"
echo " - APP_PACKAGE_TO_UPGRADE_FROM: The package version to upgrade from (defaults to none)"
diff --git a/test/test-manager/src/config/io.rs b/test/test-manager/src/config/io.rs
index 2dcc05ca0b..1aaefde71b 100644
--- a/test/test-manager/src/config/io.rs
+++ b/test/test-manager/src/config/io.rs
@@ -51,7 +51,7 @@ impl ConfigFile {
}
/// Get configuration file path
- fn get_config_path() -> Result<PathBuf, Error> {
+ pub fn get_config_path() -> Result<PathBuf, Error> {
Ok(Self::get_config_dir()?.join("config.json"))
}
diff --git a/test/test-manager/src/main.rs b/test/test-manager/src/main.rs
index cdee85e44a..694af65dc3 100644
--- a/test/test-manager/src/main.rs
+++ b/test/test-manager/src/main.rs
@@ -13,8 +13,9 @@ mod vm;
use std::net::IpAddr;
use std::{net::SocketAddr, path::PathBuf};
-use anyhow::{Context, Result};
+use anyhow::{Context, Ok, Result};
use clap::{builder::PossibleValuesParser, Parser};
+use config::ConfigFile;
use package::TargetInfo;
use tests::{config::TEST_CONFIG, get_filtered_tests};
use vm::provision;
@@ -31,28 +32,13 @@ struct Args {
#[derive(clap::Subcommand, Debug)]
enum Commands {
- /// Create or edit a VM config
- Set {
- /// Name of the VM config
- vm: String,
-
- /// VM config
- #[clap(flatten)]
- config: config::VmConfig,
- },
-
- /// Remove specified VM config
- Remove {
- /// Name of the VM config, run `test-manager list` to see available configs
- vm: String,
- },
-
- /// List available VM configurations
- List,
+ /// Manage configuration for tests and VMs
+ #[clap(subcommand)]
+ Config(ConfigArg),
/// Spawn a runner instance without running any tests
RunVm {
- /// Name of the VM config, run `test-manager list` to see available configs
+ /// Name of the VM config, run `test-manager config vm list` to see configured VMs
vm: String,
/// Run VNC server on a specified port
@@ -69,7 +55,7 @@ enum Commands {
/// Spawn a runner instance and run tests
RunTests {
- /// Name of the VM config, run `test-manager list` to see available configs
+ /// Name of the VM config, run `test-manager config vm list` to see configured VMs
#[arg(long)]
vm: String,
@@ -161,6 +147,39 @@ enum Commands {
},
}
+#[derive(clap::Subcommand, Debug)]
+enum ConfigArg {
+ /// Print the current config
+ Get,
+ /// Print the path to the current config file
+ Which,
+ /// Manage VM-specific setting
+ #[clap(subcommand)]
+ Vm(VmConfig),
+}
+
+#[derive(clap::Subcommand, Debug)]
+enum VmConfig {
+ /// Create or edit a VM config
+ Set {
+ /// Name of the VM config
+ vm: String,
+
+ /// VM config
+ #[clap(flatten)]
+ config: config::VmConfig,
+ },
+
+ /// Remove specified VM config
+ Remove {
+ /// Name of the VM config, run `test-manager config vm list` to see configured VMs
+ vm: String,
+ },
+
+ /// List available VM configurations
+ List,
+}
+
#[cfg(target_os = "linux")]
impl Args {
fn get_vnc_port(&self) -> Option<u16> {
@@ -184,33 +203,50 @@ async fn main() -> Result<()> {
.await
.context("Failed to load config")?;
match args.cmd {
- Commands::Set {
- vm,
- config: vm_config,
- } => vm::set_config(&mut config, &vm, vm_config)
- .await
- .context("Failed to edit or create VM config"),
- Commands::Remove { vm } => {
- if config.get_vm(&vm).is_none() {
- println!("No such configuration");
- return Ok(());
+ Commands::Config(config_subcommand) => match config_subcommand {
+ ConfigArg::Get => {
+ println!("{:#?}", *config);
+ Ok(())
}
- config
- .edit(|config| {
- config.vms.remove_entry(&vm);
- })
- .await
- .context("Failed to remove config entry")?;
- println!("Removed configuration \"{vm}\"");
- Ok(())
- }
- Commands::List => {
- println!("Available configurations:");
- for (vm, config) in config.vms.iter() {
- println!("{vm}: {config:#?}");
+ ConfigArg::Which => {
+ println!(
+ "{}",
+ ConfigFile::get_config_path()
+ .expect("Get config path")
+ .display()
+ );
+ Ok(())
}
- Ok(())
- }
+ ConfigArg::Vm(vm_config) => match vm_config {
+ VmConfig::Set {
+ vm,
+ config: vm_config,
+ } => vm::set_config(&mut config, &vm, vm_config)
+ .await
+ .context("Failed to edit or create VM config"),
+ VmConfig::Remove { vm } => {
+ if config.get_vm(&vm).is_none() {
+ println!("No such configuration");
+ return Ok(());
+ }
+ config
+ .edit(|config| {
+ config.vms.remove_entry(&vm);
+ })
+ .await
+ .context("Failed to remove config entry")?;
+ println!("Removed configuration \"{vm}\"");
+ Ok(())
+ }
+ VmConfig::List => {
+ println!("Configured VMs:");
+ for vm in config.vms.keys() {
+ println!("{vm}");
+ }
+ Ok(())
+ }
+ },
+ },
Commands::RunVm {
vm,
vnc,