Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
wip(refactor): use tokio for wash process
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Adossi <vadossi@cosmonic.com>
  • Loading branch information
vados-cosmonic committed Jun 2, 2023
1 parent 4cce76b commit e0e2cbe
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 150 deletions.
7 changes: 0 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ clap_complete = { workspace = true }
reqwest = { workspace = true, features = ["json", "rustls-tls"] }
tempfile = { workspace = true }
test-case = { workspace = true }
test_bin = { workspace = true }
assert-json-diff = { workspace = true }
scopeguard = { workspace = true }
sysinfo = { workspace = true }
Expand Down
11 changes: 7 additions & 4 deletions tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use std::{

use anyhow::{bail, Context, Result};
use rand::{distributions::Alphanumeric, Rng};
use tokio::net::TcpStream;
use tokio::{
net::TcpStream,
process::Command,
};

use sysinfo::SystemExt;
use tokio::process::Child;
Expand All @@ -24,8 +27,8 @@ pub(crate) const PROVIDER_HTTPSERVER_OCI_REF: &str = "wasmcloud.azurecr.io/https

/// Helper function to create the `wash` binary process
#[allow(unused)]
pub(crate) fn wash() -> std::process::Command {
test_bin::get_test_bin("wash")
pub(crate) fn wash() -> tokio::process::Command {
Command::new(env!("CARGO_BIN_EXE_wash"))
}

#[allow(unused)]
Expand Down Expand Up @@ -104,7 +107,7 @@ impl Drop for TestWashInstance {

let kill_cmd = kill_cmd.to_string();
let (_wash, down) = kill_cmd.trim_matches('"').split_once(' ').unwrap();
wash()
std::process::Command::new(env!("CARGO_BIN_EXE_wash"))
.args(vec![down])
.output()
.expect("Could not spawn wash down process");
Expand Down
92 changes: 56 additions & 36 deletions tests/integration_claims.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
mod common;
use crate::common::LOCAL_REGISTRY;
use anyhow::{Context, Result};
use assert_json_diff::assert_json_include;
use common::{get_json_output, output_to_string, test_dir_file, test_dir_with_subfolder, wash};
use serde_json::json;
use std::{
env::temp_dir,
fs::{remove_dir_all, remove_file},
};
use tokio::process::Command;

use crate::common::LOCAL_REGISTRY;
mod common;

#[test]
fn integration_claims_sign() {
#[tokio::test]
async fn integration_claims_sign() -> Result<()> {
const SUBFOLDER: &str = "claims_sign";
let sign_dir = test_dir_with_subfolder(SUBFOLDER);
const ISSUER: &str = "SAAAF62YYA6UCKZNSE7UF7GVWEHHYASDSUSSVCEEHTH3WY57DJKVXKIKOY";
Expand All @@ -20,7 +23,7 @@ fn integration_claims_sign() {
// is cleared from a signed module, so this is just as effective
// as signing an unsigned wasm
let echo = test_dir_file(SUBFOLDER, "echo.wasm");
let get_hello_wasm = wash()
let get_hello_wasm = Command::new(env!("CARGO_BIN_EXE_wash"))
.args([
"reg",
"pull",
Expand All @@ -29,11 +32,12 @@ fn integration_claims_sign() {
echo.to_str().unwrap(),
])
.output()
.expect("failed to pull echo for claims sign test");
.await
.context("failed to pull echo for claims sign test")?;
assert!(get_hello_wasm.status.success());

let signed_wasm_path = test_dir_file(SUBFOLDER, "echo_signed.wasm");
let sign_echo = wash()
let sign_echo = Command::new(env!("CARGO_BIN_EXE_wash"))
.args([
"claims",
"sign",
Expand All @@ -50,7 +54,8 @@ fn integration_claims_sign() {
signed_wasm_path.to_str().unwrap(),
])
.output()
.expect("failed to sign echo module");
.await
.context("failed to sign echo module")?;
assert!(sign_echo.status.success());
assert_eq!(
output_to_string(sign_echo).unwrap(),
Expand All @@ -61,10 +66,11 @@ fn integration_claims_sign() {
);

remove_dir_all(sign_dir).unwrap();
Ok(())
}

#[test]
fn integration_claims_inspect() {
#[tokio::test]
async fn integration_claims_inspect() -> Result<()> {
const SUBFOLDER: &str = "claims_inspect";
const ECHO_OCI: &str = "wasmcloud.azurecr.io/echo:0.2.1";
const ECHO_ACC: &str = "ACOJJN6WUP4ODD75XEBKKTCCUJJCY5ZKQ56XVKYK4BEJWGVAOOQHZMCW";
Expand All @@ -74,7 +80,7 @@ fn integration_claims_inspect() {

// Pull the echo module and push to local registry to test local inspect
let echo = test_dir_file(SUBFOLDER, "echo.wasm");
let get_hello_wasm = wash()
let get_hello_wasm = Command::new(env!("CARGO_BIN_EXE_wash"))
.args([
"reg",
"pull",
Expand All @@ -83,9 +89,10 @@ fn integration_claims_inspect() {
echo.to_str().unwrap(),
])
.output()
.expect("failed to pull echo for claims sign test");
.await
.context("failed to pull echo for claims sign test")?;
assert!(get_hello_wasm.status.success());
let push_echo = wash()
let push_echo = Command::new(env!("CARGO_BIN_EXE_wash"))
.args([
"reg",
"push",
Expand All @@ -94,11 +101,12 @@ fn integration_claims_inspect() {
"--insecure",
])
.output()
.expect("failed to push echo.wasm to local registry");
.await
.context("failed to push echo.wasm to local registry")?;
assert!(push_echo.status.success());

// Inspect local, local registry, and remote registry actor wasm
let local_inspect = wash()
let local_inspect = Command::new(env!("CARGO_BIN_EXE_wash"))
.args([
"claims",
"inspect",
Expand All @@ -107,7 +115,8 @@ fn integration_claims_inspect() {
"json",
])
.output()
.expect("failed to inspect local wasm");
.await
.context("failed to inspect local wasm")?;
assert!(local_inspect.status.success());

let local_inspect_output = get_json_output(local_inspect).unwrap();
Expand All @@ -128,10 +137,11 @@ fn integration_claims_inspect() {
expected: expected_inspect_output
);

let local_reg_inspect = wash()
let local_reg_inspect = Command::new(env!("CARGO_BIN_EXE_wash"))
.args(["claims", "inspect", echo_claims, "--insecure", "-o", "json"])
.output()
.expect("failed to inspect local registry wasm");
.await
.context("failed to inspect local registry wasm")?;
assert!(local_reg_inspect.status.success());
let local_reg_inspect_output = get_json_output(local_reg_inspect).unwrap();

Expand All @@ -140,7 +150,7 @@ fn integration_claims_inspect() {
expected: expected_inspect_output
);

let remote_inspect = wash()
let remote_inspect = Command::new(env!("CARGO_BIN_EXE_wash"))
.args([
"claims",
"inspect",
Expand All @@ -151,7 +161,8 @@ fn integration_claims_inspect() {
"json",
])
.output()
.expect("failed to inspect local registry wasm");
.await
.context("failed to inspect local registry wasm")?;
assert!(remote_inspect.status.success());
let remote_inspect_output = get_json_output(remote_inspect).unwrap();

Expand All @@ -161,10 +172,11 @@ fn integration_claims_inspect() {
);

remove_dir_all(inspect_dir).unwrap();
Ok(())
}

#[test]
fn integration_claims_inspect_cached() {
#[tokio::test]
async fn integration_claims_inspect_cached() -> Result<()> {
const ECHO_OCI: &str = "wasmcloud.azurecr.io/echo:0.2.1";
const ECHO_FAKE_OCI: &str = "foo.bar.io/echo:0.2.1";
const ECHO_FAKE_CACHED: &str = "foo_bar_io_echo_0_2_1";
Expand All @@ -175,7 +187,7 @@ fn integration_claims_inspect_cached() {
let _ = ::std::fs::create_dir_all(&echo_cache_path);
echo_cache_path.set_extension("bin");

let get_hello_wasm = wash()
let get_hello_wasm = Command::new(env!("CARGO_BIN_EXE_wash"))
.args([
"reg",
"pull",
Expand All @@ -184,10 +196,11 @@ fn integration_claims_inspect_cached() {
echo_cache_path.to_str().unwrap(),
])
.output()
.expect("failed to pull echo for claims sign test");
.await
.expect("failed to pull echo for claims sign test")?;
assert!(get_hello_wasm.status.success());

let remote_inspect = wash()
let remote_inspect = Command::new(env!("CARGO_BIN_EXE_wash"))
.args([
"claims",
"inspect",
Expand All @@ -198,7 +211,8 @@ fn integration_claims_inspect_cached() {
"json",
])
.output()
.expect("failed to inspect remote cached registry");
.await
.expect("failed to inspect remote cached registry")?;
assert!(remote_inspect.status.success());
let remote_inspect_output = get_json_output(remote_inspect).unwrap();
let expected_inspect_output = json!({
Expand All @@ -216,7 +230,7 @@ fn integration_claims_inspect_cached() {
expected: expected_inspect_output
);

let remote_inspect_no_cache = wash()
let remote_inspect_no_cache = Command::new(env!("CARGO_BIN_EXE_wash"))
.args([
"claims",
"inspect",
Expand All @@ -228,15 +242,17 @@ fn integration_claims_inspect_cached() {
"--no-cache",
])
.output()
.expect("failed to inspect remote cached registry");
.await
.expect("failed to inspect remote cached registry")?;

assert!(!remote_inspect_no_cache.status.success());

remove_file(echo_cache_path).unwrap();
Ok(())
}

#[test]
fn integration_claims_call_alias() {
#[tokio::test]
async fn integration_claims_call_alias() -> Result<()> {
const SUBFOLDER: &str = "call_alias";
let call_alias_dir = test_dir_with_subfolder(SUBFOLDER);
const ISSUER: &str = "SAADMA65NBETHOHQTXKV7XKQMXYDUS65JOWQORDR3IOMOB3UFZSDOU7TAA";
Expand All @@ -249,7 +265,7 @@ fn integration_claims_call_alias() {
// is cleared from a signed module, so this is just as effective
// as signing an unsigned wasm
let logger = test_dir_file(SUBFOLDER, "logger.wasm");
let get_wasm = wash()
let get_wasm = Command::new(env!("CARGO_BIN_EXE_wash"))
.args([
"reg",
"pull",
Expand All @@ -258,11 +274,12 @@ fn integration_claims_call_alias() {
logger.to_str().unwrap(),
])
.output()
.expect("failed to pull logger for call alias test");
.await
.context("failed to pull logger for call alias test");
assert!(get_wasm.status.success());

let signed_wasm_path = test_dir_file(SUBFOLDER, "logger_signed.wasm");
let sign_logger = wash()
let sign_logger = Command::new(env!("CARGO_BIN_EXE_wash"))
.args([
"claims",
"sign",
Expand All @@ -282,7 +299,8 @@ fn integration_claims_call_alias() {
"wasmcloud/logger_onedotzero",
])
.output()
.expect("failed to sign logger module");
.await
.context("failed to sign logger module");
assert!(sign_logger.status.success());
assert_eq!(
output_to_string(sign_logger).unwrap(),
Expand All @@ -293,7 +311,7 @@ fn integration_claims_call_alias() {
);

// inspect actor
let local_inspect = wash()
let local_inspect = Command::new(env!("CARGO_BIN_EXE_wash"))
.args([
"claims",
"inspect",
Expand All @@ -302,7 +320,8 @@ fn integration_claims_call_alias() {
"json",
])
.output()
.expect("failed to inspect local wasm");
.await
.context("failed to inspect local wasm")?;
assert!(local_inspect.status.success());
let local_inspect_output = get_json_output(local_inspect).unwrap();
let expected_json = json!({
Expand All @@ -319,4 +338,5 @@ fn integration_claims_call_alias() {
assert_json_include!(actual: local_inspect_output, expected: expected_json);

remove_dir_all(call_alias_dir).unwrap();
Ok(())
}
Loading

0 comments on commit e0e2cbe

Please sign in to comment.