From 1076ff25b6894ef0c6f75a43ea9f3d1a69ba74a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Dec 2022 21:53:34 +0100 Subject: [PATCH] Add integration tests --- lib/cli/src/commands/add.rs | 2 +- lib/cli/src/commands/config.rs | 50 +++++++++++++++++++ lib/registry/src/login.rs | 8 +-- tests/integration/cli/tests/config.rs | 72 +++++++++++++++++++++++++++ 4 files changed, 127 insertions(+), 5 deletions(-) create mode 100644 tests/integration/cli/tests/config.rs diff --git a/lib/cli/src/commands/add.rs b/lib/cli/src/commands/add.rs index b88993417..dce5191a6 100644 --- a/lib/cli/src/commands/add.rs +++ b/lib/cli/src/commands/add.rs @@ -2,7 +2,7 @@ use std::process::{Command, Stdio}; use anyhow::{Context, Error}; use clap::Parser; -use wasmer_registry::{Bindings, WasmerConfig, ProgrammingLanguage}; +use wasmer_registry::{Bindings, ProgrammingLanguage, WasmerConfig}; /// Add a WAPM package's bindings to your application. #[derive(Debug, Parser)] diff --git a/lib/cli/src/commands/config.rs b/lib/cli/src/commands/config.rs index c1db15b0a..c8a049519 100644 --- a/lib/cli/src/commands/config.rs +++ b/lib/cli/src/commands/config.rs @@ -33,6 +33,21 @@ pub enum RetrievableConfigField { Cflags, /// `pkg-config` PkgConfig, + /// `registry.url` + #[clap(name = "registry.url")] + RegistryUrl, + /// `registry.token` + #[clap(name = "registry.token")] + RegistryToken, + /// `telemetry.enabled` + #[clap(name = "telemetry.enabled")] + TelemetryEnabled, + /// `update-notifications.url` + #[clap(name = "update-notifications.enabled")] + UpdateNotificationsEnabled, + /// `proxy.url` + #[clap(name = "proxy.url")] + ProxyUrl, } /// Setting that can be stored in the wasmer config @@ -157,6 +172,41 @@ impl Config { RetrievableConfigField::Cflags => { println!("{}", cflags); } + other => { + let config = WasmerConfig::from_file() + .map_err(|e| anyhow::anyhow!("could not find config file: {e}"))?; + match other { + RetrievableConfigField::RegistryUrl => { + println!("{}", config.registry.get_current_registry()); + } + RetrievableConfigField::RegistryToken => { + if let Some(s) = config.registry.get_login_token_for_registry( + &config.registry.get_current_registry(), + ) { + println!("{s}"); + } + } + RetrievableConfigField::ProxyUrl => { + if let Some(s) = config.proxy.url.as_ref() { + println!("{s}"); + } + } + RetrievableConfigField::TelemetryEnabled => { + println!("{}", config.telemetry.enabled.to_string().replace('\"', "")); + } + RetrievableConfigField::UpdateNotificationsEnabled => { + println!( + "{}", + config + .update_notifications + .enabled + .to_string() + .replace('\"', "") + ); + } + _ => {} + } + } }, Set(s) => { let config_file = WasmerConfig::get_file_location() diff --git a/lib/registry/src/login.rs b/lib/registry/src/login.rs index e5a948600..35964b20b 100644 --- a/lib/registry/src/login.rs +++ b/lib/registry/src/login.rs @@ -11,8 +11,8 @@ pub fn login_and_save_token( ) -> Result, anyhow::Error> { let registry = format_graphql(registry); #[cfg(test)] - let mut config = WasmerConfig::from_file(test_name) - .map_err(|e| anyhow::anyhow!("config from file: {e}"))?; + let mut config = + WasmerConfig::from_file(test_name).map_err(|e| anyhow::anyhow!("config from file: {e}"))?; #[cfg(not(test))] let mut config = WasmerConfig::from_file().map_err(|e| anyhow::anyhow!("config from file: {e}"))?; @@ -26,8 +26,8 @@ pub fn login_and_save_token( let path = WasmerConfig::get_file_location(test_name) .map_err(|e| anyhow::anyhow!("get file location: {e}"))?; #[cfg(not(test))] - let path = WasmerConfig::get_file_location() - .map_err(|e| anyhow::anyhow!("get file location: {e}"))?; + let path = + WasmerConfig::get_file_location().map_err(|e| anyhow::anyhow!("get file location: {e}"))?; config.save(&path)?; crate::utils::get_username_registry_token(®istry, token) } diff --git a/tests/integration/cli/tests/config.rs b/tests/integration/cli/tests/config.rs new file mode 100644 index 000000000..9d65efde8 --- /dev/null +++ b/tests/integration/cli/tests/config.rs @@ -0,0 +1,72 @@ +use anyhow::bail; +use std::path::PathBuf; +use std::process::Command; +use wasmer_integration_tests_cli::get_wasmer_path; + +#[test] +fn config_works() -> anyhow::Result<()> { + let output = Command::new(get_wasmer_path()) + .arg("config") + .arg("get") + .arg("registry.url") + .output()?; + + assert!(output.status.success()); + + let registry_url = std::str::from_utf8(&output.stdout) + .expect("stdout is not utf8! need to handle arbitrary bytes"); + + println!("registry url {}", registry_url); + + let output = Command::new(get_wasmer_path()) + .arg("config") + .arg("set") + .arg("registry.url") + .arg("wapm.io") + .output()?; + + assert!(output.status.success()); + + let output = Command::new(get_wasmer_path()) + .arg("config") + .arg("set") + .arg("registry.url") + .arg(registry_url) + .output()?; + + assert!(output.status.success()); + + let output = Command::new(get_wasmer_path()) + .arg("config") + .arg("get") + .arg("telemetry.enabled") + .output()?; + + assert!(output.status.success()); + + let telemetry_enabled = std::str::from_utf8(&output.stdout) + .expect("stdout is not utf8! need to handle arbitrary bytes") + .trim(); + + println!("telemetry enabled {}", telemetry_enabled); + + let output = Command::new(get_wasmer_path()) + .arg("config") + .arg("set") + .arg("telemetry.enabled") + .arg("false") + .output()?; + + assert!(output.status.success()); + + let output = Command::new(get_wasmer_path()) + .arg("config") + .arg("set") + .arg("telemetry.enabled") + .arg(telemetry_enabled) + .output()?; + + assert!(output.status.success()); + + Ok(()) +}