Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions datafusion/core/tests/catalog/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ fn memory_catalog_dereg_nonempty_schema() {
assert!(cat.deregister_schema("foo", true).unwrap().is_some());
}

#[test]
fn memory_catalog_dereg_nonempty_schema_with_table_removal() {
let cat = Arc::new(MemoryCatalogProvider::new()) as Arc<dyn CatalogProvider>;

let schema = Arc::new(MemorySchemaProvider::new()) as Arc<dyn SchemaProvider>;
let test_table =
Arc::new(EmptyTable::new(Arc::new(Schema::empty()))) as Arc<dyn TableProvider>;
schema.register_table("t".into(), test_table).unwrap();

cat.register_schema("foo", schema.clone()).unwrap();
schema.deregister_table("t").unwrap();
assert!(cat.deregister_schema("foo", false).unwrap().is_some());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this just follows the pattern of the existing tests in this module, so that is good

I think a better pattern for checking errors is to verify that the error is actually the error that is expected (to make sure it isn't an error in the test setup, for example).

Something like

Suggested change
assert!(cat.deregister_schema("foo", false).unwrap().is_some());
let err = cat.deregister_schema("foo", false).unwrap_err().to_string();
assert!(err.contains("expected error message"), "Can't find expected in {err}"));

That would be a nice follow on PR

Copy link
Member Author

@caicancai caicancai Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alamb Thanks for the suggestion, but the above code will report an error

called Result::unwrap_err()on anOk value: Some(MemorySchemaProvider { tables: {} })

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And referring to other tests, they are all written in a similar way, assert!(cat.deregister_schema("foo", false).unwrap().is_some()); Maybe it would be better to keep the original writing.

}

#[test]
fn memory_catalog_dereg_empty_schema() {
let cat = Arc::new(MemoryCatalogProvider::new()) as Arc<dyn CatalogProvider>;
Expand Down