From 6eb9b46d85e6451bf4441f9250faf9b966a183b9 Mon Sep 17 00:00:00 2001 From: Dmitry Dodzin Date: Mon, 12 Aug 2024 18:57:41 +0300 Subject: [PATCH] Fix breakage in simple IncomingConfig (#2648) * Fix breakage in simple IncomingConfig * Add issue specific UT --- changelog.d/2647.fixed.md | 1 + .../config/src/feature/network/incoming.rs | 16 ++++++ mirrord/config/src/lib.rs | 52 +++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 changelog.d/2647.fixed.md diff --git a/changelog.d/2647.fixed.md b/changelog.d/2647.fixed.md new file mode 100644 index 00000000000..dc46cada71b --- /dev/null +++ b/changelog.d/2647.fixed.md @@ -0,0 +1 @@ +Fix issue introduced in #2612 that broke configs with one-value definition for IncomingConfig for network feature. diff --git a/mirrord/config/src/feature/network/incoming.rs b/mirrord/config/src/feature/network/incoming.rs index 3f69cabac81..1654e96a9d4 100644 --- a/mirrord/config/src/feature/network/incoming.rs +++ b/mirrord/config/src/feature/network/incoming.rs @@ -195,11 +195,26 @@ impl<'de> de::Visitor<'de> for IncomingFileConfigVisitor { Ok(IncomingFileConfig::Simple(Some(mode))) } + fn visit_none(self) -> Result + where + E: de::Error, + { + Ok(IncomingFileConfig::Simple(None)) + } + + fn visit_some(self, deserializer: D) -> Result + where + D: de::Deserializer<'de>, + { + Option::deserialize(deserializer).map(IncomingFileConfig::Simple) + } + fn visit_str(self, value: &str) -> Result where E: de::Error, { Deserialize::deserialize(de::value::StrDeserializer::new(value)) + .map(Some) .map(IncomingFileConfig::Simple) } @@ -208,6 +223,7 @@ impl<'de> de::Visitor<'de> for IncomingFileConfigVisitor { E: de::Error, { Deserialize::deserialize(de::value::StringDeserializer::new(value)) + .map(Some) .map(IncomingFileConfig::Simple) } diff --git a/mirrord/config/src/lib.rs b/mirrord/config/src/lib.rs index a8a1234d3d4..8e3440b007e 100644 --- a/mirrord/config/src/lib.rs +++ b/mirrord/config/src/lib.rs @@ -596,6 +596,35 @@ mod tests { } } + fn issue_2647(&self) -> &'static str { + match self { + ConfigType::Json => { + r#" + { + "feature": { + "network": { + "incoming": "steal" + } + } + } + "# + } + ConfigType::Toml => { + r#" + [feature.network] + incoming = "steal" + "# + } + ConfigType::Yaml => { + r#" + feature: + network: + incoming: steal + "# + } + } + } + fn full(&self) -> &'static str { match self { ConfigType::Json => { @@ -726,6 +755,29 @@ mod tests { assert_eq!(config, LayerFileConfig::default()); } + #[rstest] + fn issue_2647( + #[values(ConfigType::Json, ConfigType::Toml, ConfigType::Yaml)] config_type: ConfigType, + ) { + let input = config_type.issue_2647(); + let config = config_type.parse(input); + + let expect = LayerFileConfig { + feature: Some(FeatureFileConfig { + network: Some(ToggleableConfig::Config(NetworkFileConfig { + incoming: Some(ToggleableConfig::Config(IncomingFileConfig::Simple(Some( + IncomingMode::Steal, + )))), + ..Default::default() + })), + ..Default::default() + }), + ..Default::default() + }; + + assert_eq!(config, expect); + } + #[rstest] fn full( #[values(ConfigType::Json, ConfigType::Toml, ConfigType::Yaml)] config_type: ConfigType,