Skip to content

Commit

Permalink
fix: address ci issues and add integration tests...
Browse files Browse the repository at this point in the history
Signed-off-by: Ahmed <ahmedtadde@gmail.com>
  • Loading branch information
ahmedtadde committed Mar 20, 2024
1 parent ef84063 commit 6c16210
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 21 deletions.
53 changes: 53 additions & 0 deletions crates/wash-cli/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,32 @@ impl TestWashInstance {
.context("failed to parse output of `wash start actor`")
}

/// Trigger the equivalent of `wash start` on a [`TestWashInstance`]
pub(crate) async fn start_component_as_actor(
&self,
oci_ref: impl AsRef<str>,
component_id: impl AsRef<str>,
) -> Result<StartCommandOutput> {
let output = Command::new(env!("CARGO_BIN_EXE_wash"))
.args([
"start",
oci_ref.as_ref(),
component_id.as_ref(),
"--output",
"json",
"--timeout-ms",
DEFAULT_WASH_INVOCATION_TIMEOUT_MS_ARG,
"--ctl-port",
&self.nats_port.to_string(),
])
.kill_on_drop(true)
.output()
.await
.context("failed to start actor")?;
serde_json::from_slice(&output.stdout)
.context("failed to parse output of `wash start actor`")
}

/// Trigger the equivalent of `wash start provider` on a [`TestWashInstance`]
pub(crate) async fn start_provider(
&self,
Expand Down Expand Up @@ -342,6 +368,33 @@ impl TestWashInstance {
.context("failed to parse output of `wash start provider`")
}

/// Trigger the equivalent of `wash start ` on a [`TestWashInstance`]
pub(crate) async fn start_component_as_provider(
&self,
oci_ref: impl AsRef<str>,
component_id: impl AsRef<str>,
) -> Result<StartCommandOutput> {
let output = Command::new(env!("CARGO_BIN_EXE_wash"))
.args([
"start",
oci_ref.as_ref(),
component_id.as_ref(),
"--output",
"json",
"--timeout-ms",
DEFAULT_WASH_INVOCATION_TIMEOUT_MS_ARG,
"--ctl-port",
&self.nats_port.to_string(),
])
.kill_on_drop(true)
.output()
.await
.context("failed to start provider")?;

serde_json::from_slice(&output.stdout)
.context("failed to parse output of `wash start provider`")
}

/// Trigger the equivalent of `wash get hosts` on a [`TestWashInstance`]
pub(crate) async fn get_hosts(&self) -> Result<GetHostsCommandOutput> {
let output = Command::new(env!("CARGO_BIN_EXE_wash"))
Expand Down
16 changes: 16 additions & 0 deletions crates/wash-cli/tests/wash_start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ async fn integration_start_stop_actor_serial() -> Result<()> {

wash_instance.stop_actor("hello_actor_id", None).await?;

//...same thing, but using the general `wash start ...` command
wash_instance
.start_component_as_actor(HELLO_OCI_REF, "hello_actor_id")
.await?;

wash_instance.stop_actor("hello_actor_id", None).await?;

Ok(())
}

Expand All @@ -38,5 +45,14 @@ async fn integration_start_stop_provider_serial() -> Result<()> {
.stop_provider("httpserver_start_stop", None)
.await?;

//...same thing, but using the general `wash start ...` command
wash_instance
.start_component_as_provider(PROVIDER_HTTPSERVER_OCI_REF, "httpserver_start_stop")
.await?;

wash_instance
.stop_provider("httpserver_start_stop", None)
.await?;

Ok(())
}
31 changes: 10 additions & 21 deletions crates/wash-lib/src/cli/start.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use std::{collections::HashMap, fs::File};
use std::{collections::HashMap, fs::File, io::Read, path::PathBuf};

use anyhow::{anyhow, bail, Context, Result};
use clap::Parser;
use provider_archive::*;
use tokio::time::Duration;
use wascap::jwt::validate_token;
use wascap::wasm::{extract_claims, Actor};
use wascap::jwt::{validate_token, Actor};
use wascap::wasm::extract_claims;

use crate::{
actor::{scale_component, ComponentScaledInfo, ScaleComponentArgs},
cli::{input_vec_to_hashmap, CliConnectionOpts, CommandOutput},
cli::{input_vec_to_hashmap, CliConnectionOpts, CommandOutput, cached_oci_file},
common::{boxed_err_to_anyhow, find_host_id},
config::{
WashConnectionOptions, DEFAULT_NATS_TIMEOUT_MS, DEFAULT_START_ACTOR_TIMEOUT_MS,
Expand Down Expand Up @@ -457,7 +457,7 @@ pub async fn handle_start_component(cmd: StartComponentCommand) -> Result<Comman
.await?;
}

let provider = ProviderArchive::try_load(&buf);
let provider = ProviderArchive::try_load(&buf).await;

if provider.is_ok() {
return handle_start_provider(StartProviderCommand {
Expand All @@ -476,7 +476,10 @@ pub async fn handle_start_component(cmd: StartComponentCommand) -> Result<Comman

let actor = match wasmparser::Parser::new(0).parse_all(&buf).next() {
// Inspect claims inside of Wasm
Some(Ok(_)) => {
Some(Ok(wasmparser::Payload::Version {
encoding: wasmparser::Encoding::Component,
..
})) => {
let caps = extract_claims(buf)?;
let token = caps.with_context(|| {
format!(
Expand All @@ -492,21 +495,7 @@ pub async fn handle_start_component(cmd: StartComponentCommand) -> Result<Comman
)
})?;

let is_component = matches!(
wit_parsed,
Some(Ok(wasmparser::Payload::Version {
encoding: wasmparser::Encoding::Component,
..
}))
);

if is_component {
Ok(())
} else {
Err(anyhow!(
"The provided component is not a valid actor component"
))
}
Ok(())

}
_ => Err(anyhow!(
Expand Down

0 comments on commit 6c16210

Please # to comment.