Skip to content

Commit

Permalink
More test corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
zaychenko-sergei committed Oct 3, 2024
1 parent 954b7e5 commit 3fac267
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 12 deletions.
56 changes: 48 additions & 8 deletions src/adapter/graphql/tests/tests/test_gql_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,28 @@ use auth::{
DatasetActionAuthorizer,
DatasetActionUnauthorizedError,
};
use database_common::PaginationOpts;
use database_common::{NoOpDatabasePlugin, PaginationOpts};
use dill::{component, interface, Component};
use kamu::testing::MetadataFactory;
use kamu::*;
use kamu_accounts::CurrentAccountSubject;
use kamu_accounts_inmem::InMemoryAccountRepository;
use kamu_accounts::{
AccountConfig,
CurrentAccountSubject,
JwtAuthenticationConfig,
PredefinedAccountsConfig,
};
use kamu_accounts_inmem::{InMemoryAccessTokenRepository, InMemoryAccountRepository};
use kamu_accounts_services::{
AccessTokenServiceImpl,
AuthenticationServiceImpl,
LoginPasswordAuthProvider,
PredefinedAccountsRegistrator,
};
use kamu_core::*;
use kamu_datasets::DatasetEntryService;
use kamu_datasets_inmem::InMemoryDatasetEntryRepository;
use kamu_datasets_services::DatasetEntryServiceImpl;
use messaging_outbox::{Outbox, OutboxImmediateImpl};
use messaging_outbox::{register_message_dispatcher, Outbox, OutboxImmediateImpl};
use opendatafabric::*;
use time_source::SystemTimeSourceDefault;

Expand All @@ -39,15 +50,29 @@ async fn test_search_query() {
let datasets_dir = tempdir.path().join("datasets");
std::fs::create_dir(&datasets_dir).unwrap();

let cat = dill::CatalogBuilder::new()
.add::<SystemTimeSourceDefault>()
let current_account_subject = CurrentAccountSubject::new_test();
let mut predefined_accounts_config = PredefinedAccountsConfig::new();

if let CurrentAccountSubject::Logged(logged_account) = &current_account_subject {
predefined_accounts_config
.predefined
.push(AccountConfig::from_name(
logged_account.account_name.clone(),
));
} else {
panic!()
}

let mut b = dill::CatalogBuilder::new();
b.add::<SystemTimeSourceDefault>()
.add_builder(
messaging_outbox::OutboxImmediateImpl::builder()
.with_consumer_filter(messaging_outbox::ConsumerFilter::AllConsumers),
)
.bind::<dyn Outbox, OutboxImmediateImpl>()
.add::<DependencyGraphServiceInMemory>()
.add_value(CurrentAccountSubject::new_test())
.add_value(current_account_subject)
.add_value(predefined_accounts_config)
.add_builder(
DatasetRepositoryLocalFs::builder()
.with_root(datasets_dir)
Expand All @@ -60,7 +85,22 @@ async fn test_search_query() {
.add::<DatasetEntryServiceImpl>()
.add::<InMemoryDatasetEntryRepository>()
.add::<InMemoryAccountRepository>()
.build();
.add::<LoginPasswordAuthProvider>()
.add::<PredefinedAccountsRegistrator>()
.add::<AuthenticationServiceImpl>()
.add::<AccessTokenServiceImpl>()
.add::<InMemoryAccessTokenRepository>()
.add_value(JwtAuthenticationConfig::default());

NoOpDatabasePlugin::init_database_components(&mut b);

register_message_dispatcher::<DatasetLifecycleMessage>(
&mut b,
MESSAGE_PRODUCER_KAMU_CORE_DATASET_SERVICE,
);

let cat = b.build();
init_on_startup::run_startup_jobs(&cat).await.unwrap();

let create_dataset_from_snapshot = cat
.get_one::<dyn CreateDatasetFromSnapshotUseCase>()
Expand Down
13 changes: 9 additions & 4 deletions src/infra/core/tests/tests/test_query_service_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,11 +562,16 @@ async fn test_dataset_sql_unauthorized_s3() {
#[test_group::group(engine, datafusion)]
#[test_log::test(tokio::test)]
async fn test_sql_statement_not_found() {
let mut mock_authorizer = MockDatasetActionAuthorizer::new();
mock_authorizer
.expect_check_action_allowed()
.returning(|_, _| Ok(()));
mock_authorizer
.expect_get_readable_datasets()
.returning(|| Box::pin(futures::stream::empty()));

let tempdir = tempfile::tempdir().unwrap();
let catalog = create_catalog_with_local_workspace(
tempdir.path(),
MockDatasetActionAuthorizer::allowing(),
);
let catalog = create_catalog_with_local_workspace(tempdir.path(), mock_authorizer);

let _ = create_test_dataset(&catalog, tempdir.path()).await;

Expand Down

0 comments on commit 3fac267

Please sign in to comment.