-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: fresh DBs for mutation tests (#247)
<!-- The PR description should answer 2 (maybe 3) important questions: --> ### What We want to test mutations. To do this, we need fresh databases we can mutate and discard. This creates helpers for creating a fresh database. I think the abstraction could be improved, but hopefully it's not too arduous for the test writer. ### How Helpers to - make a UUID - create a DB with UUID as name - connect to that DB, import chinook - return new connection string - delete it afterwards --------- Co-authored-by: Gil Mizrahi <[email protected]>
- Loading branch information
1 parent
3f1e402
commit 01f1d00
Showing
17 changed files
with
362 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,6 @@ generated/ | |
# nix outputs | ||
/result | ||
/result-* | ||
|
||
# deployments created for testing | ||
static/temp-deploys/*.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
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
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,29 @@ | ||
pub mod common; | ||
use tests_common::deployment::{clean_up_deployment, create_fresh_deployment}; | ||
use tests_common::request::run_query; | ||
|
||
pub const POSTGRESQL_CONNECTION_STRING: &str = "postgresql://postgres:password@localhost:64002"; | ||
pub const CHINOOK_DEPLOYMENT_PATH: &str = "static/chinook-deployment.json"; | ||
|
||
/// create a fresh db then run a query against it | ||
mod basic { | ||
use super::{clean_up_deployment, create_fresh_deployment, run_query}; | ||
|
||
#[tokio::test] | ||
async fn select_by_pk() { | ||
let deployment = create_fresh_deployment( | ||
super::POSTGRESQL_CONNECTION_STRING, | ||
super::CHINOOK_DEPLOYMENT_PATH, | ||
) | ||
.await; | ||
|
||
let result = run_query( | ||
super::common::create_router_from_deployment(&deployment.deployment_path).await, | ||
"select_by_pk", | ||
) | ||
.await; | ||
|
||
clean_up_deployment(deployment).await; | ||
insta::assert_json_snapshot!(result) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
crates/ndc-postgres/tests/snapshots/mutation_tests__basic__select_by_pk.snap
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,13 @@ | ||
--- | ||
source: crates/ndc-postgres/tests/mutation_tests.rs | ||
expression: result | ||
--- | ||
[ | ||
{ | ||
"rows": [ | ||
{ | ||
"Title": "Garage Inc. (Disc 1)" | ||
} | ||
] | ||
} | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//! Deployment configuration functions used across test cases. | ||
//! Use via helpers in `mod.rs` rather than directly. | ||
//! | ||
use super::helpers::get_path_from_project_root; | ||
use serde_json::Value; | ||
use std::fs; | ||
|
||
/// Load deployment at `main_deployment_path` | ||
/// replace url with `new_postgres_url` | ||
/// save at `new_deployment_path` | ||
pub fn copy_deployment_with_new_postgres_url( | ||
main_deployment_path: &str, | ||
new_postgres_url: &str, | ||
new_deployment_path: &str, | ||
) { | ||
let full_path = get_path_from_project_root(main_deployment_path); | ||
|
||
// load and decode deployment | ||
let deployment: Value = serde_json::from_str(&fs::read_to_string(full_path).unwrap()).unwrap(); | ||
|
||
let new_json = match deployment { | ||
Value::Object(mut map) => { | ||
map.insert( | ||
"postgres_database_url".to_string(), | ||
Value::String(new_postgres_url.to_string()), | ||
); | ||
Value::Object(map) | ||
} | ||
other => other, | ||
}; | ||
|
||
let new_absolute_deployment_path = get_path_from_project_root(new_deployment_path); | ||
|
||
let new_deployment = new_json.to_string(); | ||
|
||
fs::write(new_absolute_deployment_path, new_deployment).unwrap() | ||
} | ||
|
||
/// Erase test deployment file created at `deployment_path` | ||
pub fn delete_deployment(deployment_path: &str) { | ||
let absolute_path = get_path_from_project_root(deployment_path); | ||
|
||
fs::remove_file(absolute_path).unwrap() | ||
} |
Oops, something went wrong.