Skip to content

Commit

Permalink
Fix container create model for volume mount (#187)
Browse files Browse the repository at this point in the history
* Fix container create model bug that is preventing volume mount

* cleanup

* cleanup

* Use hashmap

* Address review comment

* style
  • Loading branch information
dsajanice authored Aug 22, 2018
1 parent b6b11ae commit 0a1a47f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 4 additions & 4 deletions edgelet/docker-rs/src/models/container_create_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub struct ContainerCreateBody {
#[serde(rename = "Image", skip_serializing_if = "Option::is_none")]
image: Option<String>,
#[serde(rename = "Volumes", skip_serializing_if = "Option::is_none")]
volumes: Option<::models::ContainerConfigVolumes>,
volumes: Option<::std::collections::HashMap<String, Value>>,
/// The working directory for commands to run in.
#[serde(rename = "WorkingDir", skip_serializing_if = "Option::is_none")]
working_dir: Option<String>,
Expand Down Expand Up @@ -386,19 +386,19 @@ impl ContainerCreateBody {
self.image = None;
}

pub fn set_volumes(&mut self, volumes: ::models::ContainerConfigVolumes) {
pub fn set_volumes(&mut self, volumes: ::std::collections::HashMap<String, Value>) {
self.volumes = Some(volumes);
}

pub fn with_volumes(
mut self,
volumes: ::models::ContainerConfigVolumes,
volumes: ::std::collections::HashMap<String, Value>,
) -> ContainerCreateBody {
self.volumes = Some(volumes);
self
}

pub fn volumes(&self) -> Option<&::models::ContainerConfigVolumes> {
pub fn volumes(&self) -> Option<&::std::collections::HashMap<String, Value>> {
self.volumes.as_ref()
}

Expand Down
10 changes: 9 additions & 1 deletion edgelet/edgelet-docker/tests/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ fn container_create_handler(req: Request) -> Box<Future<Item = Response, Error =
.unwrap()
);

let volumes = create_options.volumes().unwrap();
let mut expected = ::std::collections::HashMap::new();
expected.insert("test1".to_string(), json!({}));
assert_eq!(*volumes, expected);

Ok(())
})
.map(|_| {
Expand Down Expand Up @@ -328,6 +333,8 @@ fn container_create_succeeds() {
vec![HostConfigPortBindings::new().with_host_port("8080".to_string())],
);
let memory: i64 = 3221225472;
let mut volumes = ::std::collections::HashMap::new();
volumes.insert("test1".to_string(), json!({}));
let create_options = ContainerCreateBody::new()
.with_host_config(
HostConfig::new()
Expand All @@ -342,7 +349,8 @@ fn container_create_succeeds() {
"/also/do/the/entrypoint".to_string(),
"and this".to_string(),
])
.with_env(vec!["k4=v4".to_string(), "k5=v5".to_string()]);
.with_env(vec!["k4=v4".to_string(), "k5=v5".to_string()])
.with_volumes(volumes);

let module_config = ModuleSpec::new(
"m1",
Expand Down

0 comments on commit 0a1a47f

Please sign in to comment.