@@ -143,6 +143,9 @@ where
143
143
tls_resolver. as_ref ( ) ,
144
144
& sqlite_resolver,
145
145
) ;
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.
146
149
let runtime_config: T = source. try_into ( ) . map_err ( Into :: into) ?;
147
150
148
151
Ok ( Self {
@@ -460,12 +463,11 @@ mod tests {
460
463
fn resolve_toml(
461
464
toml: toml:: Table ,
462
465
path: impl AsRef <std:: path:: Path >,
463
- ) -> ResolvedRuntimeConfig <TestFactorsRuntimeConfig > {
466
+ ) -> anyhow :: Result < ResolvedRuntimeConfig <TestFactorsRuntimeConfig > > {
464
467
ResolvedRuntimeConfig :: <TestFactorsRuntimeConfig >:: new(
465
468
toml_resolver( & toml) ,
466
469
Some ( path. as_ref( ) ) ,
467
470
)
468
- . unwrap( )
469
471
}
470
472
} ;
471
473
}
@@ -501,13 +503,16 @@ mod tests {
501
503
type = "spin"
502
504
} ;
503
505
assert_eq ! (
504
- resolve_toml( toml, "." ) . runtime_config. configured_labels( ) ,
506
+ resolve_toml( toml, "." )
507
+ . unwrap( )
508
+ . runtime_config
509
+ . configured_labels( ) ,
505
510
vec![ "default" , "foo" ]
506
511
) ;
507
512
508
513
// Test that the default label is added with an empty toml config.
509
514
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 ;
511
516
assert_eq ! ( runtime_config. configured_labels( ) , vec![ "default" ] ) ;
512
517
}
513
518
@@ -526,7 +531,7 @@ mod tests {
526
531
[ key_value_store. foo]
527
532
type = "spin"
528
533
} ;
529
- let runtime_config = resolve_toml ( toml, "config.toml" ) . runtime_config ;
534
+ let runtime_config = resolve_toml ( toml, "config.toml" ) . unwrap ( ) . runtime_config ;
530
535
assert ! ( [ "default" , "foo" ]
531
536
. iter( )
532
537
. all( |label| runtime_config. has_store_manager( label) ) ) ;
@@ -564,6 +569,7 @@ mod tests {
564
569
} )
565
570
. runtime_config (
566
571
resolve_toml ( runtime_config, tmp_dir. path ( ) . join ( "runtime-config.toml" ) )
572
+ . unwrap ( )
567
573
. runtime_config ,
568
574
) ?;
569
575
let mut state = env. build_instance_state ( ) . await ?;
@@ -589,4 +595,29 @@ mod tests {
589
595
UserProvidedPath :: Default ,
590
596
)
591
597
}
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
+ }
592
623
}
0 commit comments