Skip to content

Commit

Permalink
Fix breakage in simple IncomingConfig (#2648)
Browse files Browse the repository at this point in the history
* Fix breakage in simple IncomingConfig

* Add issue specific UT
  • Loading branch information
DmitryDodzin authored Aug 12, 2024
1 parent d9a21c1 commit 6eb9b46
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.d/2647.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix issue introduced in #2612 that broke configs with one-value definition for IncomingConfig for network feature.
16 changes: 16 additions & 0 deletions mirrord/config/src/feature/network/incoming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,26 @@ impl<'de> de::Visitor<'de> for IncomingFileConfigVisitor {
Ok(IncomingFileConfig::Simple(Some(mode)))
}

fn visit_none<E>(self) -> Result<Self::Value, E>
where
E: de::Error,
{
Ok(IncomingFileConfig::Simple(None))
}

fn visit_some<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
where
D: de::Deserializer<'de>,
{
Option::deserialize(deserializer).map(IncomingFileConfig::Simple)
}

fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
where
E: de::Error,
{
Deserialize::deserialize(de::value::StrDeserializer::new(value))
.map(Some)
.map(IncomingFileConfig::Simple)
}

Expand All @@ -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)
}

Expand Down
52 changes: 52 additions & 0 deletions mirrord/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 6eb9b46

Please sign in to comment.