use std::fs;
use std::path::{Path, PathBuf};
use std::process::Command;
fn distributed_root() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR"))
.parent()
.expect("distributed_cli has a parent directory")
.to_path_buf()
}
fn scaffold(dir_name: &str, extra_args: &[&str]) -> PathBuf {
let out_dir = Path::new(env!("CARGO_TARGET_TMPDIR")).join(dir_name);
let _ = fs::remove_dir_all(&out_dir);
let output = Command::new(env!("CARGO_BIN_EXE_dctl"))
.args([
"scaffold",
"orders",
"--path",
out_dir.to_str().unwrap(),
"--distributed-path",
distributed_root().to_str().unwrap(),
])
.args(extra_args)
.output()
.expect("dctl should run");
assert!(
output.status.success(),
"dctl scaffold {extra_args:?} failed:\n{}",
String::from_utf8_lossy(&output.stderr)
);
out_dir
}
fn cargo_check(project_dir: &Path) {
let target_dir = Path::new(env!("CARGO_TARGET_TMPDIR")).join("scaffold-compile-target");
let output = Command::new("cargo")
.args(["check", "--quiet", "--manifest-path"])
.arg(project_dir.join("Cargo.toml"))
.env("CARGO_TARGET_DIR", &target_dir)
.output()
.expect("cargo should run");
assert!(
output.status.success(),
"cargo check failed for {}:\n{}",
project_dir.display(),
String::from_utf8_lossy(&output.stderr)
);
}
#[test]
#[ignore = "compiles the scaffolded project via a nested cargo build; run in the integration job"]
fn scaffolded_http_service_compiles() {
let out_dir = scaffold(
"compile-http-postgres",
&[
"--store",
"postgres",
"--model",
"order",
"--read-models",
"--command",
"orders.place",
"--event",
"orders.shipped",
],
);
cargo_check(&out_dir);
}
#[test]
#[ignore = "compiles the scaffolded project via a nested cargo build; run in the integration job"]
fn scaffolded_http_tracing_service_compiles() {
let out_dir = scaffold(
"compile-http-tracing",
&["--transport", "http", "--store", "in-memory", "--tracing"],
);
cargo_check(&out_dir);
}
#[test]
#[ignore = "compiles the scaffolded project via a nested cargo build; run in the integration job"]
fn scaffolded_knative_service_compiles() {
let out_dir = scaffold(
"compile-knative-in-memory",
&["--transport", "knative", "--store", "in-memory"],
);
cargo_check(&out_dir);
}
#[test]
#[ignore = "compiles the scaffolded project via a nested cargo build; run in the integration job"]
fn scaffolded_knative_tracing_service_compiles() {
let out_dir = scaffold(
"compile-knative-tracing",
&[
"--transport",
"knative",
"--store",
"in-memory",
"--tracing",
],
);
cargo_check(&out_dir);
}