Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions common/src/api/external/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,7 @@ pub enum ResourceType {
IdentityProvider,
Image,
Instance,
InventoryCollection,
InstanceNetworkInterface,
InternetGateway,
InternetGatewayIpAddress,
Expand Down
38 changes: 36 additions & 2 deletions nexus/db-queries/src/db/datastore/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4738,8 +4738,20 @@ impl DataStore {
.map_err(|e| {
public_error_from_diesel(e, ErrorHandler::Server)
})?;
bail_unless!(collections.len() == 1);
let collection = collections.into_iter().next().unwrap();
let collection = match collections.len() {
0 => {
return Err(Error::ObjectNotFound {
type_name: ResourceType::InventoryCollection,
lookup_type: LookupType::ById(id.into_untyped_uuid()),
});
},
1 => collections.into_iter().next().unwrap(),
n => {
return Err(Error::internal_error(&format!(
"expected 1 collection row, got {n}"
)));
},
};
(
collection.time_started,
collection.time_done,
Expand Down Expand Up @@ -5238,6 +5250,28 @@ mod test {
logctx.cleanup_successful();
}

#[tokio::test]
async fn test_inventory_collection_read_missing_returns_not_found() {
let logctx = dev::test_setup_log("inventory_collection_read_missing");
let db = TestDatabase::new_with_datastore(&logctx.log).await;
let (opctx, datastore) = (db.opctx(), db.datastore());

let missing_id = CollectionUuid::new_v4();

let err = datastore
.inventory_collection_read(&opctx, missing_id)
.await
.expect_err("expected error for missing collection");

assert!(
matches!(err, Error::ObjectNotFound { .. }),
"expected ObjectNotFound error, got: {err:?}"
);

db.terminate().await;
logctx.cleanup_successful();
}

/// Tests inserting several collections, reading them back, and making sure
/// they look the same.
#[tokio::test]
Expand Down