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;
5
5
use std:: collections:: HashMap ;
6
6
use std:: sync:: MutexGuard ;
7
7
8
- use aw_datastore:: Datastore ;
8
+ use aw_datastore:: { Datastore , DatastoreError } ;
9
9
10
10
use crate :: endpoints:: HttpErrorJson ;
11
11
@@ -57,6 +57,7 @@ pub fn setting_get(
57
57
58
58
match datastore. get_key_value ( & setting_key) {
59
59
Ok ( value) => Ok ( Json ( serde_json:: from_str ( & value) . unwrap ( ) ) ) ,
60
+ Err ( DatastoreError :: NoSuchKey ( _) ) => Ok ( Json ( serde_json:: from_str ( "null" ) . unwrap ( ) ) ) ,
60
61
Err ( err) => Err ( err. into ( ) ) ,
61
62
}
62
63
}
Original file line number Diff line number Diff line change @@ -513,7 +513,7 @@ mod api_tests {
513
513
}
514
514
515
515
#[ test]
516
- fn test_getting_not_found_value ( ) {
516
+ fn test_get_unset_setting ( ) {
517
517
let server = setup_testserver ( ) ;
518
518
let client = Client :: untracked ( server) . expect ( "valid instance" ) ;
519
519
@@ -523,7 +523,8 @@ mod api_tests {
523
523
. get ( format ! ( "/api/0/settings/{}" , key) )
524
524
. header ( Header :: new ( "Host" , "127.0.0.1:5600" ) )
525
525
. 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" )
527
528
}
528
529
529
530
#[ test]
@@ -664,7 +665,8 @@ mod api_tests {
664
665
. get ( "/api/0/settings/test_key" )
665
666
. header ( Header :: new ( "Host" , "127.0.0.1:5600" ) )
666
667
. 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" ) ;
668
670
}
669
671
670
672
#[ test]
You can’t perform that action at this time.
0 commit comments