Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions wasmcloud-test-util/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wasmcloud-test-util"
version = "0.6.4"
version = "0.6.5"
edition = "2021"
authors = [ "wasmcloud Team" ]
license = "Apache-2.0"
Expand All @@ -10,8 +10,9 @@ repository = "https://github.com/wasmcloud/wasmcloud-test"
readme = "README.md"

[dependencies]
wasmcloud-interface-testing = "0.7.1"
wasmbus-rpc = "0.11.2"
smithy-bindgen = { git="https://github.com/wasmcloud/weld", branch="feat/smithy-bindgen" }
wasmbus-rpc = { git="https://github.com/wasmcloud/weld", rev="4faec462d1dd41efbfe95c9e2d2061a9a40f2fcc", features = [ "otel" ] }
serde_bytes = "0.11"
regex = "1"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion wasmcloud-test-util/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! cli utilities
use std::io::Write;

use crate::testing::TestResult;
use serde::Deserialize;
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
use wasmcloud_interface_testing::TestResult;

// structure for deserializing error results
#[derive(Deserialize)]
Expand Down
58 changes: 55 additions & 3 deletions wasmcloud-test-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,65 @@ pub mod provider_test;
#[cfg(not(target_arch = "wasm32"))]
pub mod cli;

// re-export testing interface
pub use wasmcloud_interface_testing as testing;

// re-export regex and nkeys
pub use nkeys;
pub use regex;

#[allow(dead_code)]
pub mod testing {

smithy_bindgen::smithy_bindgen!("testing/testing.smithy", "org.wasmcloud.interface.testing");

// after sdk is split we won't have to duplicate this code
impl Default for TestOptions {
fn default() -> TestOptions {
TestOptions {
patterns: vec![".*".to_string()],
options: std::collections::HashMap::default(),
}
}
}

pub type NamedResult<'name, T> = (&'name str, RpcResult<T>);

// convert empty RpcResult into a testResult
impl<'name, T: Serialize> From<NamedResult<'name, T>> for TestResult {
fn from(name_res: NamedResult<'name, T>) -> TestResult {
match name_res.1 {
Ok(res) => {
// TODO: if serialization of data fails, it doesn't change
// the test result, but serialization errors should be logged.
// Logging requires us to have logging set up
// (we might be running in an actor)
let data = match serde_json::to_vec(&res) {
Ok(v) => serde_json::to_vec(&serde_json::json!({ "data": v }))
.unwrap_or_default(),
Err(_) => b"".to_vec(),
};
TestResult {
name: name_res.0.to_string(),
passed: true,
snap_data: Some(data),
}
}
Err(e) => {
let data = serde_json::to_vec(&serde_json::json!(
{
"error": e.to_string(),
}
))
.ok();
TestResult {
name: name_res.0.to_string(),
passed: false,
snap_data: data,
}
}
}
}
}
}

// these macros are supported on all build targets (wasm32 et. al.)

/// check that the two expressions are equal, returning RpcError if they are not
Expand Down
16 changes: 10 additions & 6 deletions wasmcloud-test-util/src/provider_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//!
//! simple test harness to load a capability provider and test it
//!
use crate::testing::TestResult;
use anyhow::anyhow;
use async_trait::async_trait;
use futures::future::BoxFuture;
Expand Down Expand Up @@ -83,6 +82,11 @@ pub struct ProviderProcess {
}

impl ProviderProcess {
/// Returns the nats topic used by a mock actor
pub fn mock_actor_rpc_topic(&self) -> String {
wasmbus_rpc::rpc_client::rpc_topic(&self.origin(), &self.host_data.lattice_rpc_prefix)
}

/// generate the `origin` field for an Invocation. To the receiving provider,
/// the origin field looks like an actor
pub fn origin(&self) -> WasmCloudEntity {
Expand Down Expand Up @@ -404,7 +408,7 @@ macro_rules! run_selected_spawn {
let handle = tokio::runtime::Handle::current();
let all_tests = vec![".*".to_string()];
let pats : &Vec<String> = $opt.patterns.as_ref();
let mut results: Vec<TestResult> = Vec::new();
let mut results = Vec::new();

// Each test case regex (pats) is checked against all test names (tname).
// This would be simpler to use a RegexSet, but then the tests would
Expand Down Expand Up @@ -432,7 +436,7 @@ macro_rules! run_selected_spawn {
$tname(&opts).await
}
).await;
let tr:TestResult = match join {
let tr: testing::TestResult = match join {
Ok(res) => (name, res).into(),
Err(e) => (name, Err::<(),RpcError>(
RpcError::Other(format!("join error: {}", e.to_string()))
Expand Down Expand Up @@ -462,12 +466,12 @@ macro_rules! run_selected_spawn {
// calls that fail.
pub async fn run_tests(
tests: Vec<(&'static str, TestFunc)>,
) -> std::result::Result<Vec<TestResult>, Box<dyn std::error::Error>> {
let mut results: Vec<TestResult> = Vec::new();
) -> std::result::Result<Vec<crate::testing::TestResult>, Box<dyn std::error::Error>> {
let mut results = Vec::new();
let handle = tokio::runtime::Handle::current();
for (name, tfunc) in tests.into_iter() {
let rc: RpcResult<()> = handle.spawn(tfunc()).await?;
results.push(TestResult {
results.push(crate::testing::TestResult {
name: name.to_string(),
passed: rc.is_ok(),
..Default::default()
Expand Down