Add foundations for 'rojo serve' tests

This commit is contained in:
Lucien Greathouse
2019-09-03 13:48:27 -07:00
parent 6747d97d60
commit f1729163cf
7 changed files with 65 additions and 10 deletions

2
Cargo.lock generated
View File

@@ -1572,7 +1572,9 @@ dependencies = [
name = "rojo-test"
version = "0.1.0"
dependencies = [
"env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"insta 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"paste 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.9.20 (registry+https://github.com/rust-lang/crates.io-index)",
"rojo 0.5.0",

View File

@@ -10,6 +10,8 @@ insta = "0.10.0"
paste = "0.1.5"
tempfile = "3.1.0"
reqwest = "0.9.20"
env_logger = "0.6.2"
log = "0.4.8"
# We execute Rojo via std::process::Command, so depend on it so it's built!
rojo = { path = ".." }
rojo = { path = ".." }

View File

@@ -0,0 +1,9 @@
{
"name": "placeholder",
"tree": {
"$className": "StringValue",
"$properties": {
"Value": "Hello, world!"
}
}
}

View File

@@ -11,6 +11,7 @@ macro_rules! gen_build_tests {
paste::item! {
#[test]
fn [<build_ $test_name>]() {
let _ = env_logger::try_init();
run_build_test(stringify!($test_name));
}
}
@@ -54,9 +55,9 @@ fn run_build_test(test_name: &str) {
let build_test_path = get_build_tests_path();
let working_dir = get_working_dir_path();
let output_dir = tempdir().expect("couldn't create temporary directory");
let input_path = build_test_path.join(test_name);
let output_dir = tempdir().expect("couldn't create temporary directory");
let output_path = output_dir.path().join(format!("{}.rbxmx", test_name));
let exe_path = get_rojo_path();

View File

@@ -1,7 +1,5 @@
mod util;
#![cfg(test)]
#[cfg(test)]
mod build_test;
#[cfg(test)]
mod serve_test;
mod util;

View File

@@ -1 +1,41 @@
use std::path::Path;
use std::process::Command;
use crate::util::{get_rojo_path, get_serve_tests_path, get_working_dir_path};
#[test]
fn serve_test() {
let _ = env_logger::try_init();
let serve_test_path = get_serve_tests_path();
let working_dir = get_working_dir_path();
let input_path = serve_test_path.join("placeholder");
let exe_path = get_rojo_path();
let mut handle = Command::new(exe_path)
.args(&["serve", input_path.to_str().unwrap(), "--port", "35103"])
.current_dir(working_dir)
.spawn()
.expect("Couldn't start Rojo");
loop {
let mut response = match reqwest::get("http://localhost:35103/api/rojo") {
Ok(res) => res,
Err(err) => {
log::info!("Server error, retrying: {}", err);
std::thread::sleep(std::time::Duration::from_millis(30));
continue;
}
};
let text = response.text().expect("Couldn't get response text");
log::info!("Got response body: {}", text);
break;
}
handle
.kill()
.expect("Rojo server was not running at end of test");
}

View File

@@ -13,7 +13,10 @@ pub fn get_rojo_path() -> PathBuf {
pub fn get_working_dir_path() -> PathBuf {
let mut manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
assert!(manifest_dir.pop(), "Manifest directory did not have a parent");
assert!(
manifest_dir.pop(),
"Manifest directory did not have a parent"
);
manifest_dir
}
@@ -25,4 +28,4 @@ pub fn get_build_tests_path() -> PathBuf {
pub fn get_serve_tests_path() -> PathBuf {
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
manifest_dir.join("serve-tests")
}
}