diff --git a/Cargo.lock b/Cargo.lock index bcba5f4e4..e59a96ef0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -575,6 +575,8 @@ dependencies = [ "ndc-postgres", "ndc-test", "schemars", + "serde_json", + "test-each", "tests-common", "tokio", ] @@ -899,6 +901,12 @@ version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + [[package]] name = "h2" version = "0.3.21" @@ -3054,6 +3062,27 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "test-each" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d822711cf1d4a8d8adc34414c26c85f9144c692903c45a47a04ee4ffb360e5bc" +dependencies = [ + "test-each-codegen", +] + +[[package]] +name = "test-each-codegen" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad5bbe324addbdc5ee683822d0812e9bb63fbeabff10baf0d11fcfc7a0ff2122" +dependencies = [ + "glob", + "proc-macro2", + "quote", + "syn 2.0.38", +] + [[package]] name = "tests-common" version = "0.1.0" diff --git a/crates/tests/databases-tests/Cargo.toml b/crates/tests/databases-tests/Cargo.toml index f5e55630f..f326847ee 100644 --- a/crates/tests/databases-tests/Cargo.toml +++ b/crates/tests/databases-tests/Cargo.toml @@ -27,4 +27,6 @@ tests-common = { path = "../tests-common" } axum = "0.6.20" insta = { version = "1.34.0", features = ["json"] } schemars = { version = "0.8.15", features = ["smol_str", "preserve_order"] } +serde_json = "1.0.107" +test-each = "0.2.1" tokio = { version = "1.33.0", features = ["full"] } diff --git a/crates/tests/databases-tests/src/deployment_snapshot_tests.rs b/crates/tests/databases-tests/src/deployment_snapshot_tests.rs new file mode 100644 index 000000000..77e68137d --- /dev/null +++ b/crates/tests/databases-tests/src/deployment_snapshot_tests.rs @@ -0,0 +1,21 @@ +#[cfg(test)] +mod deployment_snapshots { + use ndc_postgres::configuration; + use std::fs; + use std::path::PathBuf; + + // each time we run `just generate-chinook-configuration` we save the old + // Postgres deployment in `static/deployment-snapshots`. This test parses each snapshot to + // ensure we are still able to understand old versions + #[test_each::path(glob = "static/deployment-snapshots/**/*.json", name(segments = 2))] + fn test_snapshot(deployment_path: PathBuf) { + let file = fs::File::open(deployment_path).expect("fs::File::open"); + + let deployment_json_value: serde_json::Value = + serde_json::from_reader(file).expect("serde_json::from_reader"); + + let _decoded_configuration: configuration::RawConfiguration = + serde_json::from_value(deployment_json_value.clone()) + .expect("Unable to deserialize as RawConfiguration"); + } +} diff --git a/crates/tests/databases-tests/src/lib.rs b/crates/tests/databases-tests/src/lib.rs index 253950d65..55e2a5222 100644 --- a/crates/tests/databases-tests/src/lib.rs +++ b/crates/tests/databases-tests/src/lib.rs @@ -14,3 +14,4 @@ pub mod cockroach; pub mod postgres; pub mod capabilities_tests; +pub mod deployment_snapshot_tests; diff --git a/justfile b/justfile index f41d5a056..71e5fd869 100644 --- a/justfile +++ b/justfile @@ -214,7 +214,6 @@ test *args: start-dependencies create-aurora-deployment # re-generate the deployment configuration file generate-chinook-configuration: build start-dependencies ./scripts/archive-old-deployment.sh '{{POSTGRES_CHINOOK_DEPLOYMENT}}' - exit 0 ./scripts/generate-chinook-configuration.sh 'ndc-postgres' '{{POSTGRESQL_CONNECTION_STRING}}' '{{POSTGRES_CHINOOK_DEPLOYMENT}}' ./scripts/generate-chinook-configuration.sh 'ndc-postgres' '{{CITUS_CONNECTION_STRING}}' '{{CITUS_CHINOOK_DEPLOYMENT}}' ./scripts/generate-chinook-configuration.sh 'ndc-postgres' '{{COCKROACH_CONNECTION_STRING}}' '{{COCKROACH_CHINOOK_DEPLOYMENT}}' diff --git a/scripts/archive-old-deployment.sh b/scripts/archive-old-deployment.sh index 70832e4e4..1f4adf659 100755 --- a/scripts/archive-old-deployment.sh +++ b/scripts/archive-old-deployment.sh @@ -11,12 +11,11 @@ CURRENT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" > /dev/null && echo "$P SNAPSHOT_DIR="$(realpath ${CURRENT_DIR}/../static/deployment-snapshots)" +# create snapshot dir if does not exist mkdir -p "$SNAPSHOT_DIR" +# create filename from hash of contents NEW_FILENAME="$(sha256sum "${CHINOOK_DEPLOYMENT}" | cut -f1 -d' ').json" -echo "$SNAPSHOT_DIR" - -echo "${CHINOOK_DEPLOYMENT}" - +# copy current deployment to new filename cp "${CHINOOK_DEPLOYMENT}" "${SNAPSHOT_DIR}/${NEW_FILENAME}"