Skip to content

Commit

Permalink
Restore proper configure options defaults, and add a test (#93)
Browse files Browse the repository at this point in the history
### What

By mistake, the confgure options had gotten empty defaults. The proper
defaults have now been restored.

### How

* A manual Default trait instance
* A test that checks that a 'vanilla' deployment (i.e., the one
generated from only a connectionUri) doesn't change.
  • Loading branch information
plcplc authored Oct 20, 2023
1 parent d89f196 commit 7eb46fb
Show file tree
Hide file tree
Showing 7 changed files with 3,111 additions and 12 deletions.
11 changes: 10 additions & 1 deletion crates/connectors/ndc-postgres/src/configuration/version1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct RawConfiguration {
}

/// Options which only influence how the configuration server updates the configuration
#[derive(Debug, Default, Deserialize, Serialize, JsonSchema)]
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct ConfigureOptions {
/// Schemas which are excluded from introspection. The default setting will exclude the
Expand All @@ -44,6 +44,15 @@ pub struct ConfigureOptions {
pub comparison_operator_mapping: Vec<ComparisonOperatorMapping>,
}

impl Default for ConfigureOptions {
fn default() -> ConfigureOptions {
ConfigureOptions {
excluded_schemas: default_excluded_schemas(),
comparison_operator_mapping: default_comparison_operator_mapping(),
}
}
}

/// Define the names that comparison operators will be exposed as by the automatic introspection.
#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
Expand Down
28 changes: 23 additions & 5 deletions crates/connectors/ndc-postgres/tests/configuration_tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
//! Tests that configuration generation has not changed.
//!
//! If you have changed it intentionally, run `just generate-chinook-configuration`.

pub mod common;

use std::fs;
Expand All @@ -16,7 +12,13 @@ use tests_common::schemas::check_value_conforms_to_schema;
const CONFIGURATION_QUERY: &str = include_str!("../src/configuration.sql");

#[tokio::test]
async fn test_configure() {
// Tests that configuration generation has not changed.
//
// This test does not use insta snapshots because it checks the deployment file that is shared with
// other tests.
//
// If you have changed it intentionally, run `just generate-chinook-configuration`.
async fn test_configure_is_idempotent() {
let expected_value = read_configuration();

let mut args: configuration::RawConfiguration = serde_json::from_value(expected_value.clone())
Expand All @@ -34,6 +36,22 @@ async fn test_configure() {
assert_eq!(expected_value, actual_value);
}

#[tokio::test]
async fn test_configure_initial_configuration_is_unchanged() {
let args = configuration::RawConfiguration {
connection_uri: configuration::ConnectionUri::Uri(configuration::ResolvedSecret(
common::POSTGRESQL_CONNECTION_STRING.to_string(),
)),
..configuration::RawConfiguration::empty()
};

let default_configuration = configuration::configure(args, CONFIGURATION_QUERY)
.await
.expect("configuration::configure");

insta::assert_json_snapshot!(default_configuration);
}

#[test]
fn configuration_conforms_to_the_schema() {
check_value_conforms_to_schema::<configuration::RawConfiguration>(read_configuration());
Expand Down
Loading

0 comments on commit 7eb46fb

Please sign in to comment.