From 257daaf966c8fa42bd66865a39af513dfb48df26 Mon Sep 17 00:00:00 2001 From: Johan Lorenzo Date: Mon, 1 Feb 2016 17:22:28 +0000 Subject: [PATCH 1/4] First (ugly) unit test --- src/context.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/context.rs b/src/context.rs index 482e68e0..d61de341 100644 --- a/src/context.rs +++ b/src/context.rs @@ -75,3 +75,37 @@ impl Context { (self.hostname.as_str(), self.http_port).to_socket_addrs() } } + +#[test] +#[allow(unused_variables)] +fn test_should_add_a_service() { + use service::{ Service, ServiceProperties }; + use iron::{Request, Response, IronResult}; + + struct ServiceStub; + + impl Service for ServiceStub { + fn get_properties(&self) -> ServiceProperties { + ServiceProperties { + id: '1'.to_string(), + name: "dummy service".to_string(), + description: "really nothing to see".to_string(), + http_url: '2'.to_string(), + ws_url: '3'.to_string() + } + } + fn start(&self) {} + fn stop(&self) {} + fn process_request(&self, req: &Request) -> IronResult { + return Ok(Response::new()); + } + } + + let hostname: Option = Some("localhost".to_string()); + let service = ServiceStub; + let mut foo = Context::new(false, hostname); + + assert_eq!(foo.services.is_empty(), true); + foo.add_service(Box::new(service)); + assert_eq!(foo.services.is_empty(), false); +} From 3c51fab42b68542789bd84faf953fd22997bc124 Mon Sep 17 00:00:00 2001 From: Johan Lorenzo Date: Mon, 1 Feb 2016 19:07:54 +0000 Subject: [PATCH 2/4] Add test execution on travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 8a71b2be..daace7d7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,3 +3,4 @@ rust: - nightly script: - cargo build + - RUST_BACKTRACE=1 cargo test From bf0e98e63cb66282a11cff4255c81346640d74c4 Mon Sep 17 00:00:00 2001 From: Johan Lorenzo Date: Wed, 3 Feb 2016 19:14:13 +0000 Subject: [PATCH 3/4] fixup --- src/context.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/context.rs b/src/context.rs index d61de341..bb8ddf99 100644 --- a/src/context.rs +++ b/src/context.rs @@ -33,7 +33,7 @@ impl Context { pub fn new(verbose: bool, hostname: Option) -> Context { Context { services: HashMap::new(), verbose: verbose, - hostname: hostname.unwrap_or(DEFAULT_HOSTNAME.to_owned()), + hostname: hostname.unwrap_or(DEFAULT_HOSTNAME.to_string()), http_port: DEFAULT_HTTP_PORT, ws_port: DEFAULT_WS_PORT } } @@ -101,9 +101,8 @@ fn test_should_add_a_service() { } } - let hostname: Option = Some("localhost".to_string()); let service = ServiceStub; - let mut foo = Context::new(false, hostname); + let mut foo = Context::new(false, Some("localhost".to_owned())); assert_eq!(foo.services.is_empty(), true); foo.add_service(Box::new(service)); From 3700bca2cf6db48a142348d41f2dc734531a6af3 Mon Sep 17 00:00:00 2001 From: Johan Lorenzo Date: Wed, 3 Feb 2016 19:18:36 +0000 Subject: [PATCH 4/4] f --- src/context.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/context.rs b/src/context.rs index bb8ddf99..b295ec78 100644 --- a/src/context.rs +++ b/src/context.rs @@ -33,7 +33,7 @@ impl Context { pub fn new(verbose: bool, hostname: Option) -> Context { Context { services: HashMap::new(), verbose: verbose, - hostname: hostname.unwrap_or(DEFAULT_HOSTNAME.to_string()), + hostname: hostname.unwrap_or(DEFAULT_HOSTNAME.to_owned()), http_port: DEFAULT_HTTP_PORT, ws_port: DEFAULT_WS_PORT } }