diff --git a/CHANGELOG.md b/CHANGELOG.md index 401026a1a0..9ec1e4ac41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Changed ### Added +- `hc run` now looks for the --interface flag or `HC_INTERFACE` env var if you want to specify the `http` interface [#846]((https://github.com/holochain/holochain-rust/pull/779) ### Removed ## [0.0.3] - 2019-01-13 diff --git a/cmd/src/cli/init.rs b/cmd/src/cli/init.rs index a19f9570a5..9d4967d0d6 100644 --- a/cmd/src/cli/init.rs +++ b/cmd/src/cli/init.rs @@ -100,9 +100,9 @@ pub mod tests { use super::*; use tempfile::{Builder, TempDir}; - const HOLOCHAIN_TEST_PREFIX: &str = "org.holochain.test"; + const HOLOCHAIN_TEST_PREFIX: &str = "org_holochain_test"; - fn gen_dir() -> TempDir { + pub fn gen_dir() -> TempDir { Builder::new() .prefix(HOLOCHAIN_TEST_PREFIX) .tempdir() diff --git a/cmd/src/cli/package.rs b/cmd/src/cli/package.rs index 248083882b..06195d9a9e 100644 --- a/cmd/src/cli/package.rs +++ b/cmd/src/cli/package.rs @@ -292,18 +292,9 @@ fn unpack_recurse(mut obj: Object, to: &PathBuf) -> DefaultResult<()> { // too slow! #[cfg(feature = "broken-tests")] mod tests { + use crate::cli::init::tests::gen_dir; use assert_cmd::prelude::*; use std::process::Command; - use tempfile::{Builder, TempDir}; - - const HOLOCHAIN_TEST_PREFIX: &str = "org.holochain.test"; - - fn gen_dir() -> TempDir { - Builder::new() - .prefix(HOLOCHAIN_TEST_PREFIX) - .tempdir() - .unwrap() - } #[test] fn package_and_unpack_isolated() { diff --git a/cmd/src/cli/run.rs b/cmd/src/cli/run.rs index 9f8e188b4a..848aa574eb 100644 --- a/cmd/src/cli/run.rs +++ b/cmd/src/cli/run.rs @@ -13,7 +13,13 @@ const INSTANCE_CONFIG_ID: &str = "test-instance"; const INTERFACE_CONFIG_ID: &str = "websocket-interface"; /// Starts a small container with the current application running -pub fn run(package: bool, port: u16, persist: bool, networked: bool) -> DefaultResult<()> { +pub fn run( + package: bool, + port: u16, + persist: bool, + networked: bool, + interface: String, +) -> DefaultResult<()> { if package { cli::package(true, Some(package::DEFAULT_BUNDLE_FILE_NAME.into()))?; } @@ -50,9 +56,18 @@ pub fn run(package: bool, port: u16, persist: bool, networked: bool) -> DefaultR storage, }; + let interface_type = env::var("HC_INTERFACE").ok().unwrap_or_else(|| interface); + let driver = if interface_type == String::from("websocket") { + InterfaceDriver::Websocket { port } + } else if interface_type == String::from("http") { + InterfaceDriver::Http { port } + } else { + return Err(format_err!("unknown interface type: {}", interface_type)); + }; + let interface_config = InterfaceConfiguration { id: INTERFACE_CONFIG_ID.into(), - driver: InterfaceDriver::Websocket { port }, + driver, admin: true, instances: vec![InstanceReferenceConfiguration { id: INSTANCE_CONFIG_ID.into(), @@ -113,8 +128,8 @@ pub fn run(package: bool, port: u16, persist: bool, networked: bool) -> DefaultR container.start_all_instances()?; println!( - "Holochain development container started. Running websocket server on port {}", - port + "Holochain development container started. Running {} server on port {}", + interface_type, port ); println!("Type 'exit' to stop the container and exit the program"); @@ -135,3 +150,39 @@ pub fn run(package: bool, port: u16, persist: bool, networked: bool) -> DefaultR Ok(()) } + +#[cfg(test)] +// flagged as broken for: +// 1. taking 60+ seconds +#[cfg(feature = "broken-tests")] +mod tests { + use crate::cli::init::{init, tests::gen_dir}; + use assert_cmd::prelude::*; + use std::{env, process::Command}; + + #[test] + fn test_run() { + let temp_dir = gen_dir(); + let temp_dir_path = temp_dir.path(); + let temp_dir_path_buf = temp_dir_path.to_path_buf(); + + let mut run_cmd = Command::main_binary().unwrap(); + let mut run2_cmd = Command::main_binary().unwrap(); + + let _ = init(&temp_dir_path_buf); + + assert!(env::set_current_dir(&temp_dir_path).is_ok()); + + let output = run_cmd + .args(&["run", "--package"]) + .output() + .expect("should run"); + assert_eq!(format!("{:?}",output),"Output { status: ExitStatus(ExitStatus(256)), stdout: \"\\u{1b}[1;32mCreated\\u{1b}[0m bundle file at \\\"bundle.json\\\"\\nStarting instance \\\"test-instance\\\"...\\nHolochain development container started. Running websocket server on port 8888\\nType \\\'exit\\\' to stop the container and exit the program\\n\", stderr: \"Error: EOF\\n\" }"); + + let output = run2_cmd + .args(&["run", "--interface", "http"]) + .output() + .expect("should run"); + assert_eq!(format!("{:?}",output),"Output { status: ExitStatus(ExitStatus(256)), stdout: \"Starting instance \\\"test-instance\\\"...\\nHolochain development container started. Running http server on port 8888\\nType \\\'exit\\\' to stop the container and exit the program\\n\", stderr: \"Error: EOF\\n\" }"); + } +} diff --git a/cmd/src/cli/scaffold/rust.rs b/cmd/src/cli/scaffold/rust.rs index ef3ed00554..971cf888bf 100644 --- a/cmd/src/cli/scaffold/rust.rs +++ b/cmd/src/cli/scaffold/rust.rs @@ -27,7 +27,7 @@ fn generate_cargo_toml(name: &str, contents: &str) -> DefaultResult { let authors_default = Value::from("[\"TODO\"]"); let edition_default = Value::from("\"TODO\""); - let version_default = String::from("tag = \"v0.0.3\""); + let version_default = String::from("branch = \"develop\""); let maybe_package = config.get("package"); let name = Value::from(name); diff --git a/cmd/src/cli/test.rs b/cmd/src/cli/test.rs index e920c0a7fb..ebd6b5f64d 100644 --- a/cmd/src/cli/test.rs +++ b/cmd/src/cli/test.rs @@ -62,51 +62,34 @@ pub fn test( } #[cfg(test)] -#[cfg(feature = "broken-tests")] pub mod tests { use super::*; - use crate::cli::package; - use assert_cmd::prelude::*; - use std::{env, process::Command}; - use tempfile::{Builder, TempDir}; - - #[cfg(feature = "broken-tests")] - const HOLOCHAIN_TEST_PREFIX: &str = "org_holochain_test"; - - #[cfg(feature = "broken-tests")] - pub fn gen_dir() -> TempDir { - Builder::new() - .prefix(HOLOCHAIN_TEST_PREFIX) - .tempdir() - .unwrap() - } + use crate::cli::init::{init, tests::gen_dir}; + // use assert_cmd::prelude::*; + // use std::{env, process::Command}; #[test] // flagged as broken for: // 1. taking 60+ seconds // 2. because `generate_cargo_toml` in cmd/src/scaffold/rust.rs sets the - // branch to master rather than develop and currently there's no way to + // branch to a fixed value rather than develop and currently there's no way to // adjust that on the fly. - // 3. the call to generate my_zome function doesn't quite work + // 3. because holochain-nodejs version doesn't exist yet #[cfg(feature = "broken-tests")] fn test_command_basic_test() { - let temp_space = gen_dir(); - let temp_dir_path = temp_space.path(); - let temp_dir_path_buf = temp_space.path().to_path_buf(); - - // do init first, so there's a project - Command::main_binary() - .unwrap() - .args(&["init", temp_dir_path.to_str().unwrap()]) - .assert() - .success(); + let temp_dir = gen_dir(); + let temp_dir_path = temp_dir.path(); + let temp_dir_path_buf = temp_dir_path.to_path_buf(); + + let mut gen_cmd = Command::main_binary().unwrap(); + + let _ = init(&temp_dir_path_buf); assert!(env::set_current_dir(&temp_dir_path).is_ok()); // do gen my_zome first, so there's a zome - Command::main_binary() - .unwrap() - .args(&["generate", "my_zome"]) + gen_cmd + .args(&["generate", "zomes/my_zome"]) .assert() .success(); @@ -127,19 +110,12 @@ pub mod tests { } #[test] - // flagged broken for taking 60+ seconds to run - #[cfg(feature = "broken-tests")] fn test_command_no_test_folder() { - let temp_space = gen_dir(); - let temp_dir_path = temp_space.path(); - let temp_dir_path_buf = temp_space.path().to_path_buf(); - - // do init first, so there's a project - Command::main_binary() - .unwrap() - .args(&["init", temp_dir_path.to_str().unwrap()]) - .assert() - .success(); + let temp_dir = gen_dir(); + let temp_dir_path = temp_dir.path(); + let temp_dir_path_buf = temp_dir_path.to_path_buf(); + + let _ = init(&temp_dir_path_buf); let result = test(&temp_dir_path_buf, "west", "test/index.js", false); diff --git a/cmd/src/main.rs b/cmd/src/main.rs index ee194709ae..616c068e3d 100644 --- a/cmd/src/main.rs +++ b/cmd/src/main.rs @@ -91,7 +91,7 @@ enum Cli { #[structopt( name = "run", alias = "r", - about = "Starts a development container with an open websocket" + about = "Starts a development container with a websocket or http interface" )] Run { #[structopt( @@ -111,6 +111,13 @@ enum Cli { persist: bool, #[structopt(long, help = "Use real networking")] networked: bool, + #[structopt( + long, + short, + help = "Specify interface type to use: websocket/http", + default_value = "websocket" + )] + interface: String, }, #[structopt( name = "test", @@ -163,7 +170,9 @@ fn run() -> HolochainResult<()> { port, persist, networked, - } => cli::run(package, port, persist, networked).map_err(HolochainError::Default)?, + interface, + } => cli::run(package, port, persist, networked, interface) + .map_err(HolochainError::Default)?, Cli::Test { dir, testfile,