Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejressel committed Mar 17, 2024
1 parent b21505c commit 1001c70
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 9 deletions.
87 changes: 86 additions & 1 deletion Cargo.lock

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

2 changes: 2 additions & 0 deletions cargo-pulumi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ assert_cmd.workspace = true
predicates.workspace = true
wasmtime.workspace = true
wasmtime-wasi.workspace = true
testdir = "0.9.1"
fs_extra = "1.3.0"
26 changes: 18 additions & 8 deletions cargo-pulumi/tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::process::Command;
use assert_cmd::prelude::*; // Add methods on commands

use anyhow::{Error, Ok};
use anyhow::{Error};
use fs_extra::dir::CopyOptions;
use wasmtime::component::{Component, Linker, ResourceTable};
use wasmtime::Store;
use wasmtime_wasi::preview2::WasiCtx;
Expand Down Expand Up @@ -30,9 +31,12 @@ fn errors_out_when_cargo_toml_not_available() -> Result<(), Error> {

#[test]
fn errors_out_in_invalid_package() -> Result<(), Error> {
let dir = testdir::testdir!();
fs_extra::dir::copy("tests/fixtures/example", &dir, &CopyOptions::new())?;

let s = Command::cargo_bin("cargo-pulumi")?
.args(["-p", "invalid_package"])
.current_dir("tests/fixtures/example")
.current_dir(dir.join("example"))
.assert()
.failure()
.to_string();
Expand All @@ -43,18 +47,21 @@ fn errors_out_in_invalid_package() -> Result<(), Error> {

#[test]
fn run_from_subdirectory() -> Result<(), Error> {
let dir = testdir::testdir!();
fs_extra::dir::copy("tests/fixtures/example", &dir, &CopyOptions::new())?;

Command::new("cargo")
.args(["component", "build", "-p", "common", "-p", "provider_a", "-p", "main"])
.current_dir("tests/fixtures/example")
.current_dir(dir.join("example"))
.assert()
.success();

Command::cargo_bin("cargo-pulumi")?
.current_dir("tests/fixtures/example/main")
.current_dir(dir.join("example").join("main"))
.assert()
.success();

let (mut store, plugin) = create_engine("tests/fixtures/example/target/wasm32-wasi/debug/composed.wasm")?;
let (mut store, plugin) = create_engine(dir.join("example/target/wasm32-wasi/debug/composed.wasm").to_str().unwrap())?;
let result = plugin.example_service_main_interface().call_main(&mut store)?;

assert_eq!(result, "Hello from main: [Hello from provider-a-lib: Hello from provider-a: Hello from common-lib: run_common] [Hello from common-lib: run_common]".to_string());
Expand All @@ -64,19 +71,22 @@ fn run_from_subdirectory() -> Result<(), Error> {

#[test]
fn run_from_main_directory() -> Result<(), Error> {
let dir = testdir::testdir!();
fs_extra::dir::copy("tests/fixtures/example", &dir, &CopyOptions::new())?;

Command::new("cargo")
.args(["component", "build", "-p", "common", "-p", "provider_a", "-p", "main"])
.current_dir("tests/fixtures/example")
.current_dir(dir.join("example"))
.assert()
.success();

Command::cargo_bin("cargo-pulumi")?
.args(["-p", "main"])
.current_dir("tests/fixtures/example")
.current_dir(dir.join("example"))
.assert()
.success();

let (mut store, plugin) = create_engine("tests/fixtures/example/target/wasm32-wasi/debug/composed.wasm")?;
let (mut store, plugin) = create_engine(dir.join("example/target/wasm32-wasi/debug/composed.wasm").to_str().unwrap())?;
let result = plugin.example_service_main_interface().call_main(&mut store)?;

assert_eq!(result, "Hello from main: [Hello from provider-a-lib: Hello from provider-a: Hello from common-lib: run_common] [Hello from common-lib: run_common]".to_string());
Expand Down

0 comments on commit 1001c70

Please sign in to comment.