Skip to content

Commit af6ad60

Browse files
Add tests to runtime config to confirm fields are resolved
Signed-off-by: Kate Goldenring <[email protected]>
1 parent b98c996 commit af6ad60

File tree

1 file changed

+36
-5
lines changed
  • crates/runtime-config/src

1 file changed

+36
-5
lines changed

crates/runtime-config/src/lib.rs

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ where
143143
tls_resolver.as_ref(),
144144
&sqlite_resolver,
145145
);
146+
// Note: all valid fields in the runtime config must have been referenced at
147+
// this point or the finalizer will fail due to `validate_all_keys_used`
148+
// not passing.
146149
let runtime_config: T = source.try_into().map_err(Into::into)?;
147150

148151
Ok(Self {
@@ -460,12 +463,11 @@ mod tests {
460463
fn resolve_toml(
461464
toml: toml::Table,
462465
path: impl AsRef<std::path::Path>,
463-
) -> ResolvedRuntimeConfig<TestFactorsRuntimeConfig> {
466+
) -> anyhow::Result<ResolvedRuntimeConfig<TestFactorsRuntimeConfig>> {
464467
ResolvedRuntimeConfig::<TestFactorsRuntimeConfig>::new(
465468
toml_resolver(&toml),
466469
Some(path.as_ref()),
467470
)
468-
.unwrap()
469471
}
470472
};
471473
}
@@ -501,13 +503,16 @@ mod tests {
501503
type = "spin"
502504
};
503505
assert_eq!(
504-
resolve_toml(toml, ".").runtime_config.configured_labels(),
506+
resolve_toml(toml, ".")
507+
.unwrap()
508+
.runtime_config
509+
.configured_labels(),
505510
vec!["default", "foo"]
506511
);
507512

508513
// Test that the default label is added with an empty toml config.
509514
let toml = toml::Table::new();
510-
let runtime_config = resolve_toml(toml, "config.toml").runtime_config;
515+
let runtime_config = resolve_toml(toml, "config.toml").unwrap().runtime_config;
511516
assert_eq!(runtime_config.configured_labels(), vec!["default"]);
512517
}
513518

@@ -526,7 +531,7 @@ mod tests {
526531
[key_value_store.foo]
527532
type = "spin"
528533
};
529-
let runtime_config = resolve_toml(toml, "config.toml").runtime_config;
534+
let runtime_config = resolve_toml(toml, "config.toml").unwrap().runtime_config;
530535
assert!(["default", "foo"]
531536
.iter()
532537
.all(|label| runtime_config.has_store_manager(label)));
@@ -564,6 +569,7 @@ mod tests {
564569
})
565570
.runtime_config(
566571
resolve_toml(runtime_config, tmp_dir.path().join("runtime-config.toml"))
572+
.unwrap()
567573
.runtime_config,
568574
)?;
569575
let mut state = env.build_instance_state().await?;
@@ -589,4 +595,29 @@ mod tests {
589595
UserProvidedPath::Default,
590596
)
591597
}
598+
599+
#[test]
600+
fn dirs_are_resolved() {
601+
define_test_factor!(sqlite: SqliteFactor);
602+
603+
let toml = toml::toml! {
604+
state_dir = "/foo"
605+
log_dir = "/bar"
606+
};
607+
resolve_toml(toml, "config.toml").unwrap();
608+
}
609+
610+
#[test]
611+
fn fails_to_resolve_with_unused_key() {
612+
define_test_factor!(sqlite: SqliteFactor);
613+
614+
let toml = toml::toml! {
615+
baz = "/baz"
616+
};
617+
// assert returns an error with value "unused runtime config key(s): local_app_dir"
618+
let Err(e) = resolve_toml(toml, "config.toml") else {
619+
panic!("Should not be able to resolve unknown key");
620+
};
621+
assert_eq!(e.to_string(), "unused runtime config key(s): baz");
622+
}
592623
}

0 commit comments

Comments
 (0)