mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-07 13:18:20 +00:00
Add integration tests
This commit is contained in:
@@ -2,7 +2,7 @@ use std::process::{Command, Stdio};
|
|||||||
|
|
||||||
use anyhow::{Context, Error};
|
use anyhow::{Context, Error};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use wasmer_registry::{Bindings, WasmerConfig, ProgrammingLanguage};
|
use wasmer_registry::{Bindings, ProgrammingLanguage, WasmerConfig};
|
||||||
|
|
||||||
/// Add a WAPM package's bindings to your application.
|
/// Add a WAPM package's bindings to your application.
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
|
|||||||
@@ -33,6 +33,21 @@ pub enum RetrievableConfigField {
|
|||||||
Cflags,
|
Cflags,
|
||||||
/// `pkg-config`
|
/// `pkg-config`
|
||||||
PkgConfig,
|
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
|
/// Setting that can be stored in the wasmer config
|
||||||
@@ -157,6 +172,41 @@ impl Config {
|
|||||||
RetrievableConfigField::Cflags => {
|
RetrievableConfigField::Cflags => {
|
||||||
println!("{}", 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) => {
|
Set(s) => {
|
||||||
let config_file = WasmerConfig::get_file_location()
|
let config_file = WasmerConfig::get_file_location()
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ pub fn login_and_save_token(
|
|||||||
) -> Result<Option<String>, anyhow::Error> {
|
) -> Result<Option<String>, anyhow::Error> {
|
||||||
let registry = format_graphql(registry);
|
let registry = format_graphql(registry);
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
let mut config = WasmerConfig::from_file(test_name)
|
let mut config =
|
||||||
.map_err(|e| anyhow::anyhow!("config from file: {e}"))?;
|
WasmerConfig::from_file(test_name).map_err(|e| anyhow::anyhow!("config from file: {e}"))?;
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
let mut config =
|
let mut config =
|
||||||
WasmerConfig::from_file().map_err(|e| anyhow::anyhow!("config from file: {e}"))?;
|
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)
|
let path = WasmerConfig::get_file_location(test_name)
|
||||||
.map_err(|e| anyhow::anyhow!("get file location: {e}"))?;
|
.map_err(|e| anyhow::anyhow!("get file location: {e}"))?;
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
let path = WasmerConfig::get_file_location()
|
let path =
|
||||||
.map_err(|e| anyhow::anyhow!("get file location: {e}"))?;
|
WasmerConfig::get_file_location().map_err(|e| anyhow::anyhow!("get file location: {e}"))?;
|
||||||
config.save(&path)?;
|
config.save(&path)?;
|
||||||
crate::utils::get_username_registry_token(®istry, token)
|
crate::utils::get_username_registry_token(®istry, token)
|
||||||
}
|
}
|
||||||
|
|||||||
72
tests/integration/cli/tests/config.rs
Normal file
72
tests/integration/cli/tests/config.rs
Normal 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(())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user