Skip to content

Commit

Permalink
cargo nextest
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejressel committed Mar 31, 2024
1 parent 8c78e12 commit 86ef9cd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
34 changes: 24 additions & 10 deletions cargo-pulumi/tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
use assert_cmd::prelude::*;
use std::process::Command; // Add methods on commands
use std::{env, fs};
use std::path::{Path, PathBuf};
use std::process::Command;

use crate::server::Runner;
use anyhow::Error;
use anyhow::{Context, Error};
use assert_cmd::prelude::*;
use fs_extra::dir::CopyOptions;
use wasmtime::component::{Component, Linker, ResourceTable};
use wasmtime::Store;
use wasmtime_wasi::WasiCtx;
use wasmtime_wasi::WasiCtxBuilder;
use wasmtime_wasi::WasiView;

use crate::server::Runner;

mod server {
wasmtime::component::bindgen!({
path: "tests/fixtures/example/service.wit",
Expand All @@ -35,8 +38,8 @@ 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 dir = create_test_dir("errors_out_in_invalid_package")?;
fs_extra::dir::copy("tests/fixtures/example", &dir, &CopyOptions::new().overwrite(true))?;

let s = Command::cargo_bin("cargo-pulumi")?
.args(["-p", "invalid_package"])
Expand All @@ -55,8 +58,8 @@ 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())?;
let dir = create_test_dir("run_from_subdirectory")?;
fs_extra::dir::copy("tests/fixtures/example", &dir, &CopyOptions::new().overwrite(true))?;

Command::new("cargo")
.args([
Expand Down Expand Up @@ -94,8 +97,8 @@ 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())?;
let dir = create_test_dir("run_from_main_directory")?;
fs_extra::dir::copy("tests/fixtures/example", &dir, &CopyOptions::new().overwrite(true))?;

Command::new("cargo")
.args([
Expand Down Expand Up @@ -132,6 +135,17 @@ fn run_from_main_directory() -> Result<(), Error> {
Ok(())
}

fn create_test_dir(name: &str) -> anyhow::Result<PathBuf> {
let mut dir = env::current_dir()?;
// Go to project root
while !Path::new(&dir.join("justfile")).exists() {
dir = PathBuf::from(dir.parent().ok_or(anyhow::anyhow!("Cannot find project root"))?);
}
let dir = PathBuf::from(dir).join("target").join("tests").join("cargo-pulumi").join(name);
fs::create_dir_all(&dir).context("Cannot create directory")?;
Ok(dir)
}

struct SimplePluginCtx {
table: ResourceTable,
context: WasiCtx,
Expand Down
3 changes: 2 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ build-language-plugin:

install-requirements:
rustup component add rustfmt
cargo install cargo-nextest@0.9.68 --locked || cargo-nextest --version
cargo install cargo-component@0.10.1 --locked || cargo-component --version
cargo install wasm-tools@1.201.0 --locked || wasm-tools --version

Expand Down Expand Up @@ -38,7 +39,7 @@ regenerate-providers:
cargo run -p cargo-pulumi-gen -- gen-rust --remove true --schema providers/random.json --output providers/pulumi_wasm_provider_random_rust

test:
cargo test --all
cargo nextest run --all

docs:
docker run --rm -it -p 8000:8000 -v ${PWD}:/docs squidfunk/mkdocs-material

0 comments on commit 86ef9cd

Please sign in to comment.