Skip to content

Commit

Permalink
Add dataset by id rest api tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rmn-boiko committed Oct 3, 2024
1 parent 9b2138d commit 546ec2f
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/adapter/http/tests/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod test_authentication_layer;
mod test_data_ingest;
mod test_data_query;
mod test_dataset_authorization_layer;
mod test_dataset_info;
mod test_platform_login_validate;
mod test_protocol_dataset_helpers;
mod test_routing;
Expand Down
114 changes: 114 additions & 0 deletions src/adapter/http/tests/tests/test_dataset_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// Copyright Kamu Data, Inc. and contributors. All rights reserved.
//
// Use of this software is governed by the Business Source License
// included in the LICENSE file.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0.

use chrono::Utc;
use kamu::testing::MetadataFactory;
use opendatafabric::{DatasetAlias, DatasetID, DatasetKind, DatasetName};
use serde_json::json;

use crate::harness::*;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#[test_log::test(tokio::test)]
async fn test_get_dataset_info_by_id() {
let harness = DatasetInfoHarness::new(false).await;

let dataset_alias = DatasetAlias::new(None, DatasetName::new_unchecked("foo"));
let create_result = harness
.server_harness
.cli_create_dataset_use_case()
.execute(
&dataset_alias,
MetadataFactory::metadata_block(MetadataFactory::seed(DatasetKind::Root).build())
.system_time(Utc::now())
.build_typed(),
Default::default(),
)
.await
.unwrap();

let client = async move {
let cl = reqwest::Client::new();

let res = cl
.get(&format!(
"{}datasets/{}",
harness.root_url, create_result.dataset_handle.id
))
.send()
.await
.unwrap()
.error_for_status()
.unwrap();

pretty_assertions::assert_eq!(
res.json::<serde_json::Value>().await.unwrap(),
json!({
"id": create_result.dataset_handle.id,
"datasetName": create_result.dataset_handle.alias.dataset_name,
"accountName": create_result.dataset_handle.alias.account_name,
})
);
};

await_client_server_flow!(harness.server_harness.api_server_run(), client);
}

#[test_log::test(tokio::test)]
async fn test_get_dataset_info_by_id_not_found_err() {
let harness = DatasetInfoHarness::new(false).await;

let client = async move {
let cl = reqwest::Client::new();
let dataset_id = DatasetID::new_seeded_ed25519(b"foo");

let res = cl
.get(&format!("{}datasets/{dataset_id}", harness.root_url))
.send()
.await
.unwrap();

assert_eq!(404, res.status());
assert_eq!(
format!("Dataset not found: {dataset_id}"),
res.text().await.unwrap()
);
};

await_client_server_flow!(harness.server_harness.api_server_run(), client);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

struct DatasetInfoHarness {
root_url: url::Url,
server_harness: ServerSideLocalFsHarness,
}

impl DatasetInfoHarness {
async fn new(is_multi_tenant: bool) -> Self {
let server_harness = ServerSideLocalFsHarness::new(ServerSideHarnessOptions {
multi_tenant: is_multi_tenant,
authorized_writes: true,
base_catalog: None,
})
.await;

let root_url = url::Url::parse(
format!("http://{}", server_harness.api_server_addr()).trim_end_matches('/'),
)
.unwrap();

Self {
root_url,
server_harness,
}
}
}

0 comments on commit 546ec2f

Please sign in to comment.