Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ROVER-312 Removes bug when no given config #2383

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 50 additions & 19 deletions src/command/dev/router/hot_reload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,44 @@ impl HotReloadConfig {
.map_err(|err| HotReloadError::Config { err: err.into() })?
.to_string();

// Try and get the supergraph stanza
match config.get_mut("supergraph") {
None => {
// If it doesn't exist then we need to build the mapping, and give it the
// only key we're interested in, which is listen.
let mut listen_mapping = Mapping::new();
listen_mapping.insert(
Value::String("listen".into()),
Value::String(processed_address),
);
config.as_mapping_mut().unwrap().insert(
let mut listen_mapping = Mapping::new();
listen_mapping.insert(
Value::String("listen".into()),
Value::String(processed_address.clone()),
);

let config = match config {
Value::Mapping(mut config_mapping) => {
match config_mapping.get_mut("supergraph") {
Some(Value::Mapping(supergraph_mapping)) => {
// If it does exist then we can just overwrite the existing value
// of listen with what we've worked out
supergraph_mapping.insert(
Value::String("listen".into()),
Value::String(processed_address),
);
}
_ => {
// If it doesn't exist then we need to build the mapping, and give it the
// only key we're interested in, which is listen.
config_mapping.insert(
Value::String("supergraph".into()),
Value::Mapping(listen_mapping),
);
}
}
config_mapping
}
// If config's not a mapping, then we don't have any config at all, so we
// need to build the simplest thing we can, which is just a mapping from
// supergraph to listen to the value we've computed
_ => {
let mut result = Mapping::new();
result.insert(
Value::String("supergraph".into()),
Value::Mapping(listen_mapping),
);
}
Some(supergraph_mapping) => {
// If it does exist then we can just overwrite the existing value
// of listen with what we've worked out
supergraph_mapping.as_mapping_mut().unwrap().insert(
Value::String("listen".into()),
Value::String(processed_address),
);
result
}
};

Expand Down Expand Up @@ -378,4 +394,19 @@ headers:
.unwrap()
});
}

#[rstest]
fn default_state_no_config() {
let address = RouterAddress::new(
Some(RouterHost::Default("127.0.0.1".parse().unwrap())),
Some(RouterPort::Default(4000)),
);
let overrides = HotReloadConfigOverrides::new(address);
let hot_reload_config = HotReloadConfig::new("".into(), Some(overrides));
assert_that!(hot_reload_config).is_ok().matches(|config| {
let value: Value = serde_yaml::from_str(&config.content).unwrap();
println!("{config}");
value.get("supergraph").unwrap().get("listen").unwrap() == "127.0.0.1:4000"
});
}
}