summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-01-09 16:29:10 +0100
committerGitHub <noreply@github.com>2021-01-09 10:29:10 -0500
commitae0d4e8d2d4af36cc8959ef313bf1d0054b510f6 (patch)
tree45dabd53c87d5ec74d160d2eedfca3fd5fc771be /src
parentb35a13a3985402898b726f660c470fefb64f2771 (diff)
ContainerOptionsBuilder::env() should not get owned Vec (#237)
This type signature makes it impossible to dynamically construct a Vec<String> of environment variables and pass it to the builder. This patch tries to fix that by making the function only take a reference to a slice containing the environments. Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src')
-rw-r--r--src/builder.rs26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/builder.rs b/src/builder.rs
index c14cbb7..eba3536 100644
--- a/src/builder.rs
+++ b/src/builder.rs
@@ -854,10 +854,13 @@ impl ContainerOptionsBuilder {
self
}
- pub fn env(
+ pub fn env<E, S>(
&mut self,
- envs: Vec<&str>,
- ) -> &mut Self {
+ envs: E,
+ ) -> &mut Self
+ where S: AsRef<str> + Serialize,
+ E: AsRef<[S]> + Serialize
+ {
self.params.insert("Env", json!(envs));
self
}
@@ -1698,6 +1701,23 @@ mod tests {
}
#[test]
+ fn container_options_env_dynamic() {
+ let env: Vec<String> = ["foo", "bar", "baz"]
+ .iter()
+ .map(|s| String::from(*s))
+ .collect();
+
+ let options = ContainerOptionsBuilder::new("test_image")
+ .env(&env)
+ .build();
+
+ assert_eq!(
+ r#"{"Env":["foo","bar","baz"],"HostConfig":{},"Image":"test_image"}"#,
+ options.serialize().unwrap()
+ );
+ }
+
+ #[test]
fn container_options_user() {
let options = ContainerOptionsBuilder::new("test_image")
.user("alice")