-
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.
Merge pull request #60 from hasura/paritosh/engine-1552
add native toolchain definition to connector metadata
- Loading branch information
Showing
9 changed files
with
329 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#![allow(dead_code)] // required because this is included multiple times | ||
|
||
use std::path::Path; | ||
|
||
use tokio::fs; | ||
|
||
pub async fn assert_file_ends_with_newline(path: impl AsRef<Path>) -> anyhow::Result<()> { | ||
let contents = fs::read_to_string(path).await?; | ||
assert_ends_with_newline(&contents); | ||
Ok(()) | ||
} | ||
|
||
pub fn assert_ends_with_newline(contents: &str) { | ||
assert_eq!(contents.chars().last(), Some('\n')); | ||
} |
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,181 @@ | ||
mod common; | ||
|
||
use tokio::fs; | ||
|
||
use ndc_bigquery_cli::*; | ||
use ndc_bigquery_configuration as configuration; | ||
use ndc_bigquery_configuration::ParsedConfiguration; | ||
|
||
#[tokio::test] | ||
async fn test_initialize_directory() -> anyhow::Result<()> { | ||
let dir = tempfile::tempdir()?; | ||
|
||
let context = Context { | ||
context_path: dir.path().to_owned(), | ||
environment: configuration::environment::EmptyEnvironment, | ||
release_version: None, | ||
}; | ||
run( | ||
Command::Initialize { | ||
with_metadata: false, | ||
}, | ||
context, | ||
) | ||
.await?; | ||
|
||
let configuration_schema_file_path = dir.path().join("schema.json"); | ||
assert!(configuration_schema_file_path.exists()); | ||
common::assert_file_ends_with_newline(&configuration_schema_file_path).await?; | ||
|
||
let configuration_file_path = dir.path().join("configuration.json"); | ||
assert!(configuration_file_path.exists()); | ||
let contents = fs::read_to_string(configuration_file_path).await?; | ||
common::assert_ends_with_newline(&contents); | ||
let _: ParsedConfiguration = configuration::parse_configuration(&dir).await?; | ||
|
||
let metadata_file_path = dir | ||
.path() | ||
.join(".hasura-connector") | ||
.join("connector-metadata.yaml"); | ||
assert!(!metadata_file_path.exists()); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_initialize_version_is_unchanged() -> anyhow::Result<()> { | ||
let dir = tempfile::tempdir()?; | ||
|
||
let context = Context { | ||
context_path: dir.path().to_owned(), | ||
environment: configuration::environment::EmptyEnvironment, | ||
release_version: None, | ||
}; | ||
run( | ||
Command::Initialize { | ||
with_metadata: false, | ||
}, | ||
context, | ||
) | ||
.await?; | ||
|
||
let configuration_file_path = dir.path().join("configuration.json"); | ||
assert!(configuration_file_path.exists()); | ||
let configuration_value: serde_json::Value = | ||
serde_json::from_str(fs::read_to_string(configuration_file_path).await?.as_str())?; | ||
|
||
let version = configuration_value | ||
.as_object() | ||
.unwrap() | ||
.get("version") | ||
.unwrap(); | ||
|
||
insta::assert_snapshot!(version.to_string()); | ||
Ok(()) | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_do_not_initialize_when_files_already_exist() -> anyhow::Result<()> { | ||
let dir = tempfile::tempdir()?; | ||
fs::write( | ||
dir.path().join("random.file"), | ||
"this directory is no longer empty", | ||
) | ||
.await?; | ||
|
||
let context = Context { | ||
context_path: dir.path().to_owned(), | ||
environment: configuration::environment::EmptyEnvironment, | ||
release_version: None, | ||
}; | ||
match run( | ||
Command::Initialize { | ||
with_metadata: false, | ||
}, | ||
context, | ||
) | ||
.await | ||
{ | ||
Ok(()) => panic!("Expected the command to fail."), | ||
Err(error) => match error.downcast::<Error>() { | ||
Err(input) => panic!("Expected a CLI error, but got {input}"), | ||
Ok(cli_error) => assert_eq!(cli_error, Error::DirectoryIsNotEmpty), | ||
}, | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_initialize_directory_with_metadata() -> anyhow::Result<()> { | ||
let dir = tempfile::tempdir()?; | ||
|
||
let context = Context { | ||
context_path: dir.path().to_owned(), | ||
environment: configuration::environment::EmptyEnvironment, | ||
release_version: None, | ||
}; | ||
run( | ||
Command::Initialize { | ||
with_metadata: true, | ||
}, | ||
context, | ||
) | ||
.await?; | ||
|
||
let configuration_schema_file_path = dir.path().join("schema.json"); | ||
assert!(configuration_schema_file_path.exists()); | ||
common::assert_file_ends_with_newline(&configuration_schema_file_path).await?; | ||
|
||
let configuration_file_path = dir.path().join("configuration.json"); | ||
assert!(configuration_file_path.exists()); | ||
common::assert_file_ends_with_newline(&configuration_file_path).await?; | ||
|
||
let metadata_file_path = dir | ||
.path() | ||
.join(".hasura-connector") | ||
.join("connector-metadata.yaml"); | ||
assert!(metadata_file_path.exists()); | ||
let contents = fs::read_to_string(metadata_file_path).await?; | ||
common::assert_ends_with_newline(&contents); | ||
insta::assert_snapshot!(contents); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_initialize_directory_with_metadata_and_release_version() -> anyhow::Result<()> { | ||
let dir = tempfile::tempdir()?; | ||
|
||
let context = Context { | ||
context_path: dir.path().to_owned(), | ||
environment: configuration::environment::EmptyEnvironment, | ||
release_version: Some("v1.2.3"), | ||
}; | ||
run( | ||
Command::Initialize { | ||
with_metadata: true, | ||
}, | ||
context, | ||
) | ||
.await?; | ||
|
||
let configuration_schema_file_path = dir.path().join("schema.json"); | ||
assert!(configuration_schema_file_path.exists()); | ||
common::assert_file_ends_with_newline(&configuration_schema_file_path).await?; | ||
|
||
let configuration_file_path = dir.path().join("configuration.json"); | ||
assert!(configuration_file_path.exists()); | ||
common::assert_file_ends_with_newline(&configuration_file_path).await?; | ||
|
||
let metadata_file_path = dir | ||
.path() | ||
.join(".hasura-connector") | ||
.join("connector-metadata.yaml"); | ||
assert!(metadata_file_path.exists()); | ||
let contents = fs::read_to_string(metadata_file_path).await?; | ||
common::assert_ends_with_newline(&contents); | ||
insta::assert_snapshot!(contents); | ||
|
||
Ok(()) | ||
} |
43 changes: 43 additions & 0 deletions
43
crates/cli/tests/snapshots/initialize_tests__initialize_directory_with_metadata.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,43 @@ | ||
--- | ||
source: crates/cli/tests/initialize_tests.rs | ||
expression: contents | ||
--- | ||
packagingDefinition: | ||
type: PrebuiltDockerImage | ||
dockerImage: ghcr.io/hasura/ndc-bigquery:latest | ||
supportedEnvironmentVariables: | ||
- name: HASURA_BIGQUERY_SERVICE_KEY | ||
description: The BigQuery service key | ||
- name: HASURA_BIGQUERY_PROJECT_ID | ||
description: The BigQuery project ID/name | ||
- name: HASURA_BIGQUERY_DATASET_ID | ||
description: The BigQuery dataset ID/name | ||
commands: | ||
update: hasura-ndc-bigquery update | ||
cliPlugin: | ||
name: ndc-bigquery | ||
version: latest | ||
dockerComposeWatch: | ||
- path: ./ | ||
target: /etc/connector | ||
action: sync+restart | ||
nativeToolchainDefinition: | ||
commands: | ||
start: | ||
type: ShellScript | ||
bash: |- | ||
#!/usr/bin/env bash | ||
set -eu -o pipefail | ||
HASURA_CONFIGURATION_DIRECTORY="$HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH" "$HASURA_DDN_NATIVE_CONNECTOR_DIR/ndc-bigquery" serve | ||
powershell: |- | ||
$ErrorActionPreference = "Stop" | ||
$env:HASURA_CONFIGURATION_DIRECTORY="$env:HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH"; & "$env:HASURA_DDN_NATIVE_CONNECTOR_DIR\ndc-bigquery.exe" serve | ||
update: | ||
type: ShellScript | ||
bash: |- | ||
#!/usr/bin/env bash | ||
set -eu -o pipefail | ||
"$HASURA_DDN_NATIVE_CONNECTOR_PLUGIN_DIR/hasura-ndc-bigquery" update | ||
powershell: |- | ||
$ErrorActionPreference = "Stop" | ||
& "$env:HASURA_DDN_NATIVE_CONNECTOR_PLUGIN_DIR\hasura-ndc-bigquery.exe" update |
43 changes: 43 additions & 0 deletions
43
...s/snapshots/initialize_tests__initialize_directory_with_metadata_and_release_version.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,43 @@ | ||
--- | ||
source: crates/cli/tests/initialize_tests.rs | ||
expression: contents | ||
--- | ||
packagingDefinition: | ||
type: PrebuiltDockerImage | ||
dockerImage: ghcr.io/hasura/ndc-bigquery:v1.2.3 | ||
supportedEnvironmentVariables: | ||
- name: HASURA_BIGQUERY_SERVICE_KEY | ||
description: The BigQuery service key | ||
- name: HASURA_BIGQUERY_PROJECT_ID | ||
description: The BigQuery project ID/name | ||
- name: HASURA_BIGQUERY_DATASET_ID | ||
description: The BigQuery dataset ID/name | ||
commands: | ||
update: hasura-ndc-bigquery update | ||
cliPlugin: | ||
name: ndc-bigquery | ||
version: v1.2.3 | ||
dockerComposeWatch: | ||
- path: ./ | ||
target: /etc/connector | ||
action: sync+restart | ||
nativeToolchainDefinition: | ||
commands: | ||
start: | ||
type: ShellScript | ||
bash: |- | ||
#!/usr/bin/env bash | ||
set -eu -o pipefail | ||
HASURA_CONFIGURATION_DIRECTORY="$HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH" "$HASURA_DDN_NATIVE_CONNECTOR_DIR/ndc-bigquery" serve | ||
powershell: |- | ||
$ErrorActionPreference = "Stop" | ||
$env:HASURA_CONFIGURATION_DIRECTORY="$env:HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH"; & "$env:HASURA_DDN_NATIVE_CONNECTOR_DIR\ndc-bigquery.exe" serve | ||
update: | ||
type: ShellScript | ||
bash: |- | ||
#!/usr/bin/env bash | ||
set -eu -o pipefail | ||
"$HASURA_DDN_NATIVE_CONNECTOR_PLUGIN_DIR/hasura-ndc-bigquery" update | ||
powershell: |- | ||
$ErrorActionPreference = "Stop" | ||
& "$env:HASURA_DDN_NATIVE_CONNECTOR_PLUGIN_DIR\hasura-ndc-bigquery.exe" update |
5 changes: 5 additions & 0 deletions
5
crates/cli/tests/snapshots/initialize_tests__initialize_version_is_unchanged.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,5 @@ | ||
--- | ||
source: crates/cli/tests/initialize_tests.rs | ||
expression: version.to_string() | ||
--- | ||
1 |