Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lswith committed Apr 22, 2023
1 parent f6a8869 commit e2b01b8
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ struct Empty {}
fn optional_hashset_from_str<'de, D: Deserializer<'de>>(
d: D,
) -> Result<Option<HashSet<String>>, D::Error> {
let res = <Option<HashMap<String, Empty>>>::deserialize(d)?;
let res: Option<HashMap<String, Empty>> = Option::deserialize(d)?;
let res = res.map(|h| h.into_keys().collect());
Ok(res)
}
Expand Down Expand Up @@ -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<HashSet<String>>,

/// Entries are in the format of `VARNAME=VARVALUE`.
#[serde(skip_serializing_if = "Vec::is_empty")]
pub env: Vec<String>,
#[serde(skip_serializing_if = "is_option_vec_empty")]
pub env: Option<Vec<String>>,

/// Default arguments to the entrypoint of the container.
#[serde(skip_serializing_if = "Vec::is_empty")]
pub cmd: Vec<String>,
#[serde(skip_serializing_if = "is_option_vec_empty")]
pub cmd: Option<Vec<String>>,

/// 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<String>,
#[serde(skip_serializing_if = "is_option_vec_empty")]
pub entrypoint: Option<Vec<String>>,

/// 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<HashSet<String>>,

Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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()
});
Expand Down

0 comments on commit e2b01b8

Please sign in to comment.