Add integration tests

This commit is contained in:
Felix Schütt
2022-12-15 21:53:34 +01:00
parent 11f6c430cb
commit 1076ff25b6
4 changed files with 127 additions and 5 deletions

View File

@@ -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)]

View File

@@ -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()

View File

@@ -11,8 +11,8 @@ pub fn login_and_save_token(
) -> Result<Option<String>, 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(&registry, token)
}

View File

@@ -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(())
}