Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rmn-boiko committed Oct 3, 2024
1 parent 30872f8 commit d439086
Show file tree
Hide file tree
Showing 19 changed files with 154 additions and 200 deletions.
2 changes: 1 addition & 1 deletion resources/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ To regenerate this schema from existing code, use the following command:
* `inspect` — Group of commands for exploring dataset metadata
* `list [ls]` — List all datasets in the workspace
* `log` — Shows dataset metadata history
* `login`Authenticates with a remote ODF server interactively
* `login`Authentiates with a remote ODF server interactively
* `logout` — Logs out from a remote Kamu server
* `new` — Creates a new dataset manifest from a template
* `notebook` — Starts the notebook server for exploring the data in the workspace
Expand Down
3 changes: 3 additions & 0 deletions resources/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,9 @@ type SaveDatasetEnvVarResultSuccess implements SaveDatasetEnvVarResult {

input ScheduleInput @oneOf {
timeDelta: TimeDeltaInput
"""
Supported CRON syntax: min hour dayOfMonth month dayOfWeek
"""
cron5ComponentExpression: String
}

Expand Down
2 changes: 2 additions & 0 deletions src/adapter/http/src/data/account_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use axum::extract::Extension;
use axum::response::Json;
use chrono::{DateTime, Utc};
use database_common_macros::transactional_handler;
use dill::Catalog;
use http_common::*;
use kamu_accounts::{
Expand Down Expand Up @@ -68,6 +69,7 @@ impl From<Account> for Response {

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

#[transactional_handler]
pub async fn account_handler(
Extension(catalog): Extension<Catalog>,
) -> Result<Json<Response>, ApiError> {
Expand Down
39 changes: 19 additions & 20 deletions src/adapter/http/tests/harness/server_side_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ pub(crate) trait ServerSideHarness {

fn api_server_addr(&self) -> String;

fn api_server_account(&self) -> Account;

fn system_time_source(&self) -> &SystemTimeSourceStub;

async fn api_server_run(self) -> Result<(), InternalError>;
Expand All @@ -82,28 +84,25 @@ pub(crate) struct ServerSideHarnessOptions {
pub base_catalog: Option<dill::Catalog>,
}

pub(crate) struct ServerSideHarnessOverrides {
pub mock_authentication_service: Option<MockAuthenticationService>,
}

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

pub(crate) fn server_authentication_mock() -> MockAuthenticationService {
MockAuthenticationService::resolving_token(
kamu_accounts::DUMMY_ACCESS_TOKEN,
Account {
id: AccountID::new_seeded_ed25519(SERVER_ACCOUNT_NAME.as_bytes()),
account_name: AccountName::new_unchecked(SERVER_ACCOUNT_NAME),
account_type: AccountType::User,
display_name: SERVER_ACCOUNT_NAME.to_string(),
email: None,
avatar_url: None,
registered_at: Utc::now(),
is_admin: false,
provider: String::from(PROVIDER_PASSWORD),
provider_identity_key: String::from(SERVER_ACCOUNT_NAME),
},
)
pub(crate) fn server_authentication_mock(account: &Account) -> MockAuthenticationService {
MockAuthenticationService::resolving_token(kamu_accounts::DUMMY_ACCESS_TOKEN, account.clone())
}

pub(crate) fn get_server_account() -> Account {
Account {
id: AccountID::new_seeded_ed25519(SERVER_ACCOUNT_NAME.as_bytes()),
account_name: AccountName::new_unchecked(SERVER_ACCOUNT_NAME),
account_type: AccountType::User,
display_name: SERVER_ACCOUNT_NAME.to_string(),
email: None,
avatar_url: None,
registered_at: Utc::now(),
is_admin: false,
provider: String::from(PROVIDER_PASSWORD),
provider_identity_key: String::from(SERVER_ACCOUNT_NAME),
}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
22 changes: 12 additions & 10 deletions src/adapter/http/tests/harness/server_side_local_fs_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use kamu::{
ObjectStoreRegistryImpl,
RemoteRepositoryRegistryImpl,
};
use kamu_accounts::{AuthenticationService, MockAuthenticationService};
use kamu_accounts::{Account, AuthenticationService, MockAuthenticationService};
use messaging_outbox::DummyOutboxImpl;
use opendatafabric::{AccountName, DatasetAlias, DatasetHandle};
use tempfile::TempDir;
Expand All @@ -48,10 +48,10 @@ use url::Url;
use super::{
create_cli_user_catalog,
create_web_user_catalog,
get_server_account,
server_authentication_mock,
ServerSideHarness,
ServerSideHarnessOptions,
ServerSideHarnessOverrides,
TestAPIServer,
SERVER_ACCOUNT_NAME,
};
Expand All @@ -65,13 +65,11 @@ pub(crate) struct ServerSideLocalFsHarness {
api_server: TestAPIServer,
options: ServerSideHarnessOptions,
time_source: SystemTimeSourceStub,
account: Account,
}

impl ServerSideLocalFsHarness {
pub async fn new(
options: ServerSideHarnessOptions,
overrides: ServerSideHarnessOverrides,
) -> Self {
pub async fn new(options: ServerSideHarnessOptions) -> Self {
let tempdir = tempfile::tempdir().unwrap();

let datasets_dir = tempdir.path().join("datasets");
Expand All @@ -83,6 +81,8 @@ impl ServerSideLocalFsHarness {
let cache_dir = tempdir.path().join("cache");
std::fs::create_dir(&cache_dir).unwrap();

let account = get_server_account();

let time_source = SystemTimeSourceStub::new();
let (base_catalog, listener) = {
let mut b = match &options.base_catalog {
Expand All @@ -93,9 +93,6 @@ impl ServerSideLocalFsHarness {
let addr = SocketAddr::from(([127, 0, 0, 1], 0));
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
let base_url_rest = format!("http://{}", listener.local_addr().unwrap());
let mock_auth_service = overrides
.mock_authentication_service
.unwrap_or(server_authentication_mock());

b.add_value(RunInfoDir::new(run_info_dir))
.add_value(CacheDir::new(cache_dir))
Expand All @@ -110,7 +107,7 @@ impl ServerSideLocalFsHarness {
)
.bind::<dyn DatasetRepository, DatasetRepositoryLocalFs>()
.bind::<dyn DatasetRepositoryWriter, DatasetRepositoryLocalFs>()
.add_value(mock_auth_service)
.add_value(server_authentication_mock(&account))
.bind::<dyn AuthenticationService, MockAuthenticationService>()
.add_value(ServerUrlConfig::new_test(Some(&base_url_rest)))
.add::<CompactionServiceImpl>()
Expand Down Expand Up @@ -139,6 +136,7 @@ impl ServerSideLocalFsHarness {
api_server,
options,
time_source,
account,
}
}

Expand Down Expand Up @@ -196,6 +194,10 @@ impl ServerSideHarness for ServerSideLocalFsHarness {
self.api_server.local_addr().to_string()
}

fn api_server_account(&self) -> Account {
self.account.clone()
}

fn dataset_url_with_scheme(&self, dataset_alias: &DatasetAlias, scheme: &str) -> Url {
let api_server_address = self.api_server_addr();
Url::from_str(
Expand Down
13 changes: 11 additions & 2 deletions src/adapter/http/tests/harness/server_side_s3_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use kamu::{
ObjectStoreBuilderS3,
ObjectStoreRegistryImpl,
};
use kamu_accounts::{AuthenticationService, MockAuthenticationService};
use kamu_accounts::{Account, AuthenticationService, MockAuthenticationService};
use messaging_outbox::DummyOutboxImpl;
use opendatafabric::{AccountName, DatasetAlias, DatasetHandle};
use time_source::{SystemTimeSource, SystemTimeSourceStub};
Expand All @@ -49,6 +49,7 @@ use url::Url;
use super::{
create_cli_user_catalog,
create_web_user_catalog,
get_server_account,
server_authentication_mock,
ServerSideHarness,
ServerSideHarnessOptions,
Expand All @@ -66,6 +67,7 @@ pub(crate) struct ServerSideS3Harness {
options: ServerSideHarnessOptions,
time_source: SystemTimeSourceStub,
_temp_dir: tempfile::TempDir,
account: Account,
}

impl ServerSideS3Harness {
Expand All @@ -79,6 +81,8 @@ impl ServerSideS3Harness {

let time_source = SystemTimeSourceStub::new();

let account = get_server_account();

let (base_catalog, listener) = {
let addr = SocketAddr::from(([127, 0, 0, 1], 0));
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
Expand All @@ -98,7 +102,7 @@ impl ServerSideS3Harness {
)
.bind::<dyn DatasetRepository, DatasetRepositoryS3>()
.bind::<dyn DatasetRepositoryWriter, DatasetRepositoryS3>()
.add_value(server_authentication_mock())
.add_value(server_authentication_mock(&account))
.bind::<dyn AuthenticationService, MockAuthenticationService>()
.add_value(ServerUrlConfig::new_test(Some(&base_url_rest)))
.add::<CompactionServiceImpl>()
Expand Down Expand Up @@ -129,6 +133,7 @@ impl ServerSideS3Harness {
options,
time_source,
_temp_dir: temp_dir,
account,
}
}

Expand Down Expand Up @@ -204,6 +209,10 @@ impl ServerSideHarness for ServerSideS3Harness {
self.api_server.local_addr().to_string()
}

fn api_server_account(&self) -> Account {
self.account.clone()
}

fn dataset_layout(&self, dataset_handle: &DatasetHandle) -> DatasetLayout {
DatasetLayout::new(
self.internal_bucket_folder_path()
Expand Down
12 changes: 0 additions & 12 deletions src/adapter/http/tests/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ macro_rules! test_client_server_local_fs_harness_permutations {
multi_tenant: false,
authorized_writes: true,
base_catalog: None,
},
ServerSideHarnessOverrides {
mock_authentication_service: None,
}).await,
)
.await;
Expand All @@ -57,9 +54,6 @@ macro_rules! test_client_server_local_fs_harness_permutations {
multi_tenant: true,
authorized_writes: true,
base_catalog: None,
},
ServerSideHarnessOverrides {
mock_authentication_service: None,
}).await,
)
.await;
Expand All @@ -75,9 +69,6 @@ macro_rules! test_client_server_local_fs_harness_permutations {
multi_tenant: false,
authorized_writes: true,
base_catalog: None,
},
ServerSideHarnessOverrides {
mock_authentication_service: None,
}).await,
)
.await;
Expand All @@ -93,9 +84,6 @@ macro_rules! test_client_server_local_fs_harness_permutations {
multi_tenant: true,
authorized_writes: true,
base_catalog: None,
},
ServerSideHarnessOverrides {
mock_authentication_service: None,
}).await,
)
.await;
Expand Down
43 changes: 17 additions & 26 deletions src/adapter/http/tests/tests/test_account_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0.

use kamu_accounts::{Account, MockAuthenticationService, DEFAULT_ACCOUNT_ID, DUMMY_ACCESS_TOKEN};
use kamu_accounts::DUMMY_ACCESS_TOKEN;
use kamu_core::RunInfoDir;
use serde_json::json;

Expand Down Expand Up @@ -37,6 +37,7 @@ async fn test_get_account_info_with_wrong_token() {
#[test_log::test(tokio::test)]
async fn test_get_account_info() {
let harness = AccountInfoHarness::new(false).await;
let expected_account = harness.server_harness.api_server_account();

let client = async move {
let cl = reqwest::Client::new();
Expand All @@ -48,20 +49,19 @@ async fn test_get_account_info() {
.await
.unwrap();

let dummy_account = Account::dummy();
pretty_assertions::assert_eq!(
res.json::<serde_json::Value>().await.unwrap(),
json!({
"accountName": dummy_account.account_name,
"accountType": dummy_account.account_type,
"id": dummy_account.id,
"avatarUrl": dummy_account.avatar_url,
"displayName": dummy_account.display_name,
"email": dummy_account.email,
"isAdmin": dummy_account.is_admin,
"provider": dummy_account.provider,
"providerIdentityKey": dummy_account.provider_identity_key,
"registeredAt": dummy_account.registered_at
"accountName": expected_account.account_name,
"accountType": expected_account.account_type,
"id": expected_account.id,
"avatarUrl": expected_account.avatar_url,
"displayName": expected_account.display_name,
"email": expected_account.email,
"isAdmin": expected_account.is_admin,
"provider": expected_account.provider,
"providerIdentityKey": expected_account.provider_identity_key,
"registeredAt": expected_account.registered_at
})
);
};
Expand All @@ -87,20 +87,11 @@ impl AccountInfoHarness {
.add_value(RunInfoDir::new(run_info_dir.path()))
.build();

let server_harness = ServerSideLocalFsHarness::new(
ServerSideHarnessOptions {
multi_tenant: is_multi_tenant,
authorized_writes: true,
base_catalog: Some(catalog),
},
ServerSideHarnessOverrides {
mock_authentication_service: Some(MockAuthenticationService::resolving_by_id(
&DEFAULT_ACCOUNT_ID,
DUMMY_ACCESS_TOKEN,
Account::dummy(),
)),
},
)
let server_harness = ServerSideLocalFsHarness::new(ServerSideHarnessOptions {
multi_tenant: is_multi_tenant,
authorized_writes: true,
base_catalog: Some(catalog),
})
.await;

let root_url = url::Url::parse(
Expand Down
15 changes: 5 additions & 10 deletions src/adapter/http/tests/tests/test_data_ingest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,16 +601,11 @@ impl DataIngestHarness {
.add_value(FileUploadLimitConfig::new_in_bytes(1000))
.build();

let server_harness = ServerSideLocalFsHarness::new(
ServerSideHarnessOptions {
multi_tenant: true,
authorized_writes: true,
base_catalog: Some(catalog),
},
ServerSideHarnessOverrides {
mock_authentication_service: None,
},
)
let server_harness = ServerSideLocalFsHarness::new(ServerSideHarnessOptions {
multi_tenant: true,
authorized_writes: true,
base_catalog: Some(catalog),
})
.await;

let system_time = Utc.with_ymd_and_hms(2050, 1, 1, 12, 0, 0).unwrap();
Expand Down
15 changes: 5 additions & 10 deletions src/adapter/http/tests/tests/test_data_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,11 @@ impl Harness {
.add::<EngineProvisionerNull>()
.build();

let server_harness = ServerSideLocalFsHarness::new(
ServerSideHarnessOptions {
multi_tenant: true,
authorized_writes: true,
base_catalog: Some(catalog),
},
ServerSideHarnessOverrides {
mock_authentication_service: None,
},
)
let server_harness = ServerSideLocalFsHarness::new(ServerSideHarnessOptions {
multi_tenant: true,
authorized_writes: true,
base_catalog: Some(catalog),
})
.await;

let system_time = Utc.with_ymd_and_hms(2050, 1, 1, 12, 0, 0).unwrap();
Expand Down
Loading

0 comments on commit d439086

Please sign in to comment.