Skip to content

Commit

Permalink
add hab-director
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Parfitt <dparfitt@chef.io>
  • Loading branch information
Dave Parfitt committed May 19, 2016
1 parent f1d2148 commit a604f3f
Show file tree
Hide file tree
Showing 17 changed files with 2,509 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ all: image ## builds all the project's Rust components
$(run) sh -c 'cd components/core && cargo build'
$(run) sh -c 'cd components/depot-core && cargo build'
$(run) sh -c 'cd components/depot-client && cargo build'
$(run) sh -c 'cd components/director && cargo build'
$(MAKE) bin

test: image ## tests the project's Rust components
Expand All @@ -59,6 +60,7 @@ test: image ## tests the project's Rust components
$(run) sh -c 'cd components/common && cargo test'
$(run) sh -c 'cd components/sup && cargo test '
$(run) sh -c 'cd components/depot && cargo test'
$(run) sh -c 'cd components/director && cargo test'

unit: image ## executes the components' unit test suites
$(run) sh -c 'cd components/builder-api && cargo test --lib'
Expand All @@ -69,6 +71,7 @@ unit: image ## executes the components' unit test suites
$(run) sh -c 'cd components/core && cargo test'
$(run) sh -c 'cd components/depot-core && cargo test --lib'
$(run) sh -c 'cd components/depot-client && cargo test --lib'
$(run) sh -c 'cd components/director && cargo test --lib'
$(run) sh -c 'cd components/common && cargo test --lib'
$(run) sh -c 'cd components/sup && cargo test --lib'
$(run) sh -c 'cd components/depot && cargo test --lib'
Expand All @@ -89,6 +92,7 @@ clean: ## cleans up the project tree
$(run) sh -c 'cd components/depot-client && cargo clean'
$(run) sh -c 'cd components/depot-core && cargo clean'
$(run) sh -c 'cd components/depot && cargo clean'
$(run) sh -c 'cd components/director && cargo clean'
$(run) sh -c 'cd components/hab && cargo clean'
$(run) sh -c 'cd components/net && cargo clean'
$(run) sh -c 'cd components/sodiumoxide && cargo clean'
Expand Down
5 changes: 5 additions & 0 deletions components/core/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ pub fn cache_src_path(fs_root_path: Option<&Path>) -> PathBuf {
}
}

/// Returns the root path containing all runtime service directories and files
pub fn svc_root() -> PathBuf {
Path::new("/").join(SVC_PATH).to_path_buf()
}

/// Returns the root path for a given service's configuration, files, and data.
pub fn svc_path(service_name: &str) -> PathBuf {
Path::new("/").join(SVC_PATH).join(service_name)
Expand Down
28 changes: 28 additions & 0 deletions components/core/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ impl ServiceGroup {
organization: organization,
}
}

// returns ".org" if self.organization is Some, otherwise an empty string
pub fn dotted_org_or_empty(&self) -> String {
self.organization.as_ref().map_or("".to_string(), |s| format!(".{}", &s))
}
}

impl fmt::Display for ServiceGroup {
Expand Down Expand Up @@ -149,4 +154,27 @@ mod test {
fn from_str_not_enough_periods() {
ServiceGroup::from_str("oh-noes").unwrap();
}

#[test]
fn service_groups_with_org() {
let x = ServiceGroup::from_str("foo.bar").unwrap();
assert!(x.service == "foo".to_string());
assert!(x.group == "bar".to_string());
assert!(x.organization.is_none());

let y = ServiceGroup::from_str("foo.bar@baz").unwrap();
assert!(y.service == "foo".to_string());
assert!(y.group == "bar".to_string());
assert!(y.organization.unwrap() == "baz");

assert!(ServiceGroup::from_str("foo.bar@").is_err());
assert!(ServiceGroup::from_str("f.oo.bar@baz").is_err());
assert!(ServiceGroup::from_str("foo@baz").is_err());
}

#[test]
fn org_or_empty() {
assert!("" == ServiceGroup::from_str("foo.bar").unwrap().dotted_org_or_empty());
assert!(".baz" == ServiceGroup::from_str("foo.bar@baz").unwrap().dotted_org_or_empty());
}
}
Loading

0 comments on commit a604f3f

Please sign in to comment.