Skip to content

Commit 5878551

Browse files
committed
fix(meta/test): in a testing function, return a fake error when trying to get abasent key
1 parent b62118e commit 5878551

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/meta/api/src/kv_api_utils.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use common_meta_app::schema::DatabaseMeta;
2020
use common_meta_app::schema::DatabaseNameIdent;
2121
use common_meta_app::schema::TableNameIdent;
2222
use common_meta_app::share::*;
23+
use common_meta_types::anyerror::AnyError;
2324
use common_meta_types::app_error::AppError;
2425
use common_meta_types::app_error::ShareHasNoGrantedDatabase;
2526
use common_meta_types::app_error::UnknownDatabase;
@@ -486,6 +487,7 @@ where
486487
}
487488

488489
/// Get existing value by key. Panic if key is absent.
490+
/// This function is only used for testing.
489491
pub async fn get_kv_data<T>(
490492
kv_api: &(impl KVApi + ?Sized),
491493
key: &impl KVApiKey,
@@ -500,7 +502,10 @@ where
500502
return Ok(s);
501503
};
502504

503-
unreachable!("failed to get {}", key.to_key())
505+
Err(MetaError::Fatal(AnyError::error(format!(
506+
"failed to get {}",
507+
key.to_key()
508+
))))
504509
}
505510

506511
pub async fn get_object_shared_by_share_ids(

src/meta/api/src/schema_api_test_suite.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2374,11 +2374,13 @@ impl SchemaApiTestSuite {
23742374
for db_id in old_id_list.iter() {
23752375
let id_key = DatabaseId { db_id: *db_id };
23762376
let id_mapping = DatabaseIdToName { db_id: *db_id };
2377+
23772378
let meta_res: Result<DatabaseMeta, MetaError> =
23782379
get_kv_data(mt.as_kv_api(), &id_key).await;
2380+
assert!(meta_res.is_err());
2381+
23792382
let mapping_res: Result<DatabaseNameIdent, MetaError> =
23802383
get_kv_data(mt.as_kv_api(), &id_mapping).await;
2381-
assert!(meta_res.is_err());
23822384
assert!(mapping_res.is_err());
23832385
}
23842386

0 commit comments

Comments
 (0)