File tree Expand file tree Collapse file tree 2 files changed +7
-4
lines changed
Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ use rocket::State;
55use std:: collections:: HashMap ;
66use std:: sync:: MutexGuard ;
77
8- use aw_datastore:: Datastore ;
8+ use aw_datastore:: { Datastore , DatastoreError } ;
99
1010use crate :: endpoints:: HttpErrorJson ;
1111
@@ -57,6 +57,7 @@ pub fn setting_get(
5757
5858 match datastore. get_key_value ( & setting_key) {
5959 Ok ( value) => Ok ( Json ( serde_json:: from_str ( & value) . unwrap ( ) ) ) ,
60+ Err ( DatastoreError :: NoSuchKey ( _) ) => Ok ( Json ( serde_json:: from_str ( "null" ) . unwrap ( ) ) ) ,
6061 Err ( err) => Err ( err. into ( ) ) ,
6162 }
6263}
Original file line number Diff line number Diff line change @@ -513,7 +513,7 @@ mod api_tests {
513513 }
514514
515515 #[ test]
516- fn test_getting_not_found_value ( ) {
516+ fn test_get_unset_setting ( ) {
517517 let server = setup_testserver ( ) ;
518518 let client = Client :: untracked ( server) . expect ( "valid instance" ) ;
519519
@@ -523,7 +523,8 @@ mod api_tests {
523523 . get ( format ! ( "/api/0/settings/{}" , key) )
524524 . header ( Header :: new ( "Host" , "127.0.0.1:5600" ) )
525525 . dispatch ( ) ;
526- assert_eq ! ( res. status( ) , rocket:: http:: Status :: NotFound ) ;
526+ assert_eq ! ( res. status( ) , rocket:: http:: Status :: Ok ) ;
527+ assert_eq ! ( res. into_string( ) . unwrap( ) , "null" )
527528 }
528529
529530 #[ test]
@@ -664,7 +665,8 @@ mod api_tests {
664665 . get ( "/api/0/settings/test_key" )
665666 . header ( Header :: new ( "Host" , "127.0.0.1:5600" ) )
666667 . dispatch ( ) ;
667- assert_eq ! ( res. status( ) , rocket:: http:: Status :: NotFound ) ;
668+ assert_eq ! ( res. status( ) , rocket:: http:: Status :: Ok ) ;
669+ assert_eq ! ( res. into_string( ) . unwrap( ) , "null" ) ;
668670 }
669671
670672 #[ test]
You can’t perform that action at this time.
0 commit comments