From e2b01b804c4316ec72c341765bf105c399049fb9 Mon Sep 17 00:00:00 2001 From: Luke Swithenbank Date: Sat, 22 Apr 2023 12:57:49 +0800 Subject: [PATCH] fix tests --- src/config.rs | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/config.rs b/src/config.rs index dc865a0a..548db710 100644 --- a/src/config.rs +++ b/src/config.rs @@ -142,7 +142,7 @@ struct Empty {} fn optional_hashset_from_str<'de, D: Deserializer<'de>>( d: D, ) -> Result>, D::Error> { - let res = >>::deserialize(d)?; + let res: Option> = Option::deserialize(d)?; let res = res.map(|h| h.into_keys().collect()); Ok(res) } @@ -193,28 +193,30 @@ pub struct Config { #[serde( skip_serializing_if = "is_option_hashset_empty", deserialize_with = "optional_hashset_from_str", - serialize_with = "serialize_optional_hashset" + serialize_with = "serialize_optional_hashset", + default )] pub exposed_ports: Option>, /// Entries are in the format of `VARNAME=VARVALUE`. - #[serde(skip_serializing_if = "Vec::is_empty")] - pub env: Vec, + #[serde(skip_serializing_if = "is_option_vec_empty")] + pub env: Option>, /// Default arguments to the entrypoint of the container. - #[serde(skip_serializing_if = "Vec::is_empty")] - pub cmd: Vec, + #[serde(skip_serializing_if = "is_option_vec_empty")] + pub cmd: Option>, /// A list of arguments to use as the command to execute when /// the container starts.. - #[serde(skip_serializing_if = "Vec::is_empty")] - pub entrypoint: Vec, + #[serde(skip_serializing_if = "is_option_vec_empty")] + pub entrypoint: Option>, /// A set of directories describing where the process is likely write data specific to a container instance. #[serde( skip_serializing_if = "is_option_hashset_empty", deserialize_with = "optional_hashset_from_str", - serialize_with = "serialize_optional_hashset" + serialize_with = "serialize_optional_hashset", + default )] pub volumes: Option>, @@ -371,17 +373,17 @@ mod tests { let config = Config { user: Some("alice".into()), exposed_ports: Some(HashSet::from_iter(vec!["8080/tcp".into()])), - env: vec![ + env: Some(vec![ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin".into(), "FOO=oci_is_a".into(), "BAR=well_written_spec".into(), - ], - cmd: vec![ + ]), + cmd: Some(vec![ "--foreground".into(), "--config".into(), "/etc/my-app.d/default.cfg".into(), - ], - entrypoint: vec!["/bin/my-app-binary".into()], + ]), + entrypoint: Some(vec!["/bin/my-app-binary".into()]), volumes: Some(HashSet::from_iter(vec![ "/var/job-result-data".into(), "/var/log/my-app-logs".into(), @@ -492,7 +494,9 @@ mod tests { fn minimal_config2() -> ConfigFile { let config = Some(Config { - env: vec!["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin".into()], + env: Some(vec![ + "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin".into(), + ]), working_dir: Some("/".into()), ..Config::default() });