-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
239 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
172 changes: 172 additions & 0 deletions
172
src/domain/datasets/services/tests/tests/test_dataset_env_var_service_impl.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
// 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 std::assert_matches::assert_matches; | ||
use std::sync::Arc; | ||
|
||
use dill::{Catalog, CatalogBuilder}; | ||
use kamu_datasets::{ | ||
DatasetEnvVarRepository, | ||
DatasetEnvVarService, | ||
DatasetEnvVarUpsertResult, | ||
DatasetEnvVarValue, | ||
DatasetEnvVarsConfig, | ||
UpsertDatasetEnvVarStatus, | ||
}; | ||
use kamu_datasets_inmem::InMemoryDatasetEnvVarRepository; | ||
use kamu_datasets_services::DatasetEnvVarServiceImpl; | ||
use opendatafabric::DatasetID; | ||
use secrecy::SecretString; | ||
use time_source::SystemTimeSourceDefault; | ||
|
||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
#[test_log::test(tokio::test)] | ||
async fn test_upsert_dataset_env_var() { | ||
let harness = DatasetEnvVarServiceHarness::new(); | ||
|
||
let create_result = harness | ||
.dataset_env_var_service | ||
.upsert_dataset_env_var( | ||
"foo_key", | ||
&DatasetEnvVarValue::Secret(SecretString::from("foo_value")), | ||
&DatasetID::new_seeded_ed25519(b"foo"), | ||
) | ||
.await; | ||
|
||
assert_matches!( | ||
create_result, | ||
Ok(DatasetEnvVarUpsertResult { | ||
status: UpsertDatasetEnvVarStatus::Created, | ||
.. | ||
}) | ||
); | ||
|
||
// ToDo: currently we are not checking if the secret values are equal, so we | ||
// are updating the same value in case they are both secret | ||
// The blocker is postgres implementation which requires one more additional | ||
// db request to fetch the value from the db and compare it with the new value | ||
let update_up_to_date_result = harness | ||
.dataset_env_var_service | ||
.upsert_dataset_env_var( | ||
"foo_key", | ||
&DatasetEnvVarValue::Secret(SecretString::from("foo_value")), | ||
&DatasetID::new_seeded_ed25519(b"foo"), | ||
) | ||
.await; | ||
|
||
assert_matches!( | ||
update_up_to_date_result, | ||
Ok(DatasetEnvVarUpsertResult { | ||
status: UpsertDatasetEnvVarStatus::Updated, | ||
.. | ||
}) | ||
); | ||
|
||
// Change visibility of env var from secret to regular | ||
let update_modified_result = harness | ||
.dataset_env_var_service | ||
.upsert_dataset_env_var( | ||
"foo_key", | ||
&DatasetEnvVarValue::Regular("foo_value".to_owned()), | ||
&DatasetID::new_seeded_ed25519(b"foo"), | ||
) | ||
.await; | ||
|
||
assert_matches!( | ||
update_modified_result, | ||
Ok(DatasetEnvVarUpsertResult { | ||
status: UpsertDatasetEnvVarStatus::Updated, | ||
.. | ||
}) | ||
); | ||
|
||
// Try to modify the regular value of the env var with the same value will | ||
// return up to date | ||
let update_modified_result = harness | ||
.dataset_env_var_service | ||
.upsert_dataset_env_var( | ||
"foo_key", | ||
&DatasetEnvVarValue::Regular("foo_value".to_owned()), | ||
&DatasetID::new_seeded_ed25519(b"foo"), | ||
) | ||
.await; | ||
|
||
assert_matches!( | ||
update_modified_result, | ||
Ok(DatasetEnvVarUpsertResult { | ||
status: UpsertDatasetEnvVarStatus::UpToDate, | ||
.. | ||
}) | ||
); | ||
|
||
let update_modified_result = harness | ||
.dataset_env_var_service | ||
.upsert_dataset_env_var( | ||
"foo_key", | ||
&DatasetEnvVarValue::Regular("new_foo_value".to_owned()), | ||
&DatasetID::new_seeded_ed25519(b"foo"), | ||
) | ||
.await; | ||
|
||
assert_matches!( | ||
update_modified_result, | ||
Ok(DatasetEnvVarUpsertResult { | ||
status: UpsertDatasetEnvVarStatus::Updated, | ||
.. | ||
}) | ||
); | ||
|
||
// Change visibility of env var back to secret | ||
let update_modified_result = harness | ||
.dataset_env_var_service | ||
.upsert_dataset_env_var( | ||
"foo_key", | ||
&DatasetEnvVarValue::Secret(SecretString::from("new_foo_value")), | ||
&DatasetID::new_seeded_ed25519(b"foo"), | ||
) | ||
.await; | ||
|
||
assert_matches!( | ||
update_modified_result, | ||
Ok(DatasetEnvVarUpsertResult { | ||
status: UpsertDatasetEnvVarStatus::Updated, | ||
.. | ||
}) | ||
); | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
struct DatasetEnvVarServiceHarness { | ||
_catalog: Catalog, | ||
dataset_env_var_service: Arc<dyn DatasetEnvVarService>, | ||
} | ||
|
||
impl DatasetEnvVarServiceHarness { | ||
fn new() -> Self { | ||
let catalog = { | ||
let mut b = CatalogBuilder::new(); | ||
|
||
b.add::<DatasetEnvVarServiceImpl>(); | ||
b.add_value(InMemoryDatasetEnvVarRepository::new()); | ||
b.bind::<dyn DatasetEnvVarRepository, InMemoryDatasetEnvVarRepository>(); | ||
|
||
b.add::<SystemTimeSourceDefault>(); | ||
b.add_value(DatasetEnvVarsConfig::sample()); | ||
|
||
b.build() | ||
}; | ||
|
||
Self { | ||
dataset_env_var_service: catalog.get_one().unwrap(), | ||
_catalog: catalog, | ||
} | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...c6c174cc3cbd5eaf76a865e8baa92ca999fb.json → ...387c3d021b0248fd1a2fea65e4e76bc24d36.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...c7ea26b2e7e8a920332e6676abff09192f87.json → ...ca0f03c0f7b5ffa11ba0236ab1b0a0324eef.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
.../sqlite/.sqlx/query-140e91ce459e7759cbd0f57dc8f723cbffa51b784536d2045db121a64d795e2e.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters