-
Notifications
You must be signed in to change notification settings - Fork 8
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
10 changed files
with
196 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#![cfg(feature = "mock_transport_framework")] | ||
use dotenv::dotenv; | ||
use std::fs; | ||
use std::path::Path; | ||
mod setup; | ||
|
||
#[tokio::test] | ||
#[ignore] | ||
async fn create_query_delete_table() { | ||
dotenv().ok(); | ||
|
||
let cargo_root = std::env::var("CARGO_MANIFEST_DIR").expect("Set by cargo"); | ||
let kql_root = Path::new(&cargo_root).join("tests/inputs/e2e"); | ||
|
||
let (client, database) = setup::create_kusto_client("data_create_query_delete_table") | ||
.await | ||
.unwrap(); | ||
|
||
let filename = kql_root.join("01_prepare_table.kql"); | ||
let query = fs::read_to_string(filename).expect("Something went wrong reading the file"); | ||
let response = client | ||
.execute_command(&database, query) | ||
.into_future() | ||
.await | ||
.unwrap(); | ||
|
||
println!("{:?}", response); | ||
|
||
let filename = kql_root.join("02_drop_table.kql"); | ||
let query = fs::read_to_string(filename).expect("Something went wrong reading the file"); | ||
let response = client | ||
.execute_command(&database, query) | ||
.into_future() | ||
.await | ||
.unwrap(); | ||
|
||
println!("{:?}", response) | ||
} |
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,3 @@ | ||
.set KustoRsTest <| | ||
let text="Hello, World!"; | ||
print str=text |
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 @@ | ||
.drop table KustoRsTest |
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,91 @@ | ||
#![cfg(feature = "mock_transport_framework")] | ||
use azure_core::auth::{TokenCredential, TokenResponse}; | ||
use azure_core::Error as CoreError; | ||
use azure_identity::token_credentials::{ClientSecretCredential, TokenCredentialOptions}; | ||
use azure_kusto_data::client::{KustoClient, KustoClientOptions}; | ||
use chrono::Utc; | ||
use oauth2::AccessToken; | ||
use std::error::Error; | ||
use std::sync::Arc; | ||
|
||
pub struct DummyCredential {} | ||
|
||
#[async_trait::async_trait] | ||
impl TokenCredential for DummyCredential { | ||
async fn get_token(&self, _resource: &str) -> Result<TokenResponse, CoreError> { | ||
Ok(TokenResponse::new( | ||
AccessToken::new("some dummy token".to_string()), | ||
Utc::now(), | ||
)) | ||
} | ||
} | ||
|
||
pub async fn create_kusto_client( | ||
transaction_name: &str, | ||
) -> Result<(KustoClient, String), Box<dyn Error + Send + Sync>> { | ||
let client_id = (std::env::var(azure_core::mock::TESTING_MODE_KEY).as_deref() | ||
== Ok(azure_core::mock::TESTING_MODE_RECORD)) | ||
.then(get_client_id) | ||
.unwrap_or_else(String::new); | ||
|
||
let client_secret = (std::env::var(azure_core::mock::TESTING_MODE_KEY).as_deref() | ||
== Ok(azure_core::mock::TESTING_MODE_RECORD)) | ||
.then(get_client_secret) | ||
.unwrap_or_else(String::new); | ||
|
||
let tenant_id = (std::env::var(azure_core::mock::TESTING_MODE_KEY).as_deref() | ||
== Ok(azure_core::mock::TESTING_MODE_RECORD)) | ||
.then(get_tenant_id) | ||
.unwrap_or_else(String::new); | ||
|
||
let service_url = (std::env::var(azure_core::mock::TESTING_MODE_KEY).as_deref() | ||
== Ok(azure_core::mock::TESTING_MODE_RECORD)) | ||
.then(get_service_url) | ||
.unwrap_or_else(String::new); | ||
|
||
let database = (std::env::var(azure_core::mock::TESTING_MODE_KEY).as_deref() | ||
== Ok(azure_core::mock::TESTING_MODE_RECORD)) | ||
.then(get_database) | ||
.unwrap_or_else(String::new); | ||
|
||
let options = KustoClientOptions::new_with_transaction_name(transaction_name.to_string()); | ||
|
||
let credential: Arc<dyn TokenCredential> = if std::env::var(azure_core::mock::TESTING_MODE_KEY) | ||
.as_deref() | ||
== Ok(azure_core::mock::TESTING_MODE_RECORD) | ||
{ | ||
Arc::new(ClientSecretCredential::new( | ||
tenant_id.to_string(), | ||
client_id.to_string(), | ||
client_secret.to_string(), | ||
TokenCredentialOptions::default(), | ||
)) | ||
} else { | ||
Arc::new(DummyCredential {}) | ||
}; | ||
|
||
Ok(( | ||
KustoClient::new_with_options(service_url, credential, options).unwrap(), | ||
database, | ||
)) | ||
} | ||
|
||
fn get_service_url() -> String { | ||
std::env::var("KUSTO_SERVICE_URL").expect("Set env variable KUSTO_SERVICE_URL first!") | ||
} | ||
|
||
fn get_database() -> String { | ||
std::env::var("KUSTO_DATABASE").expect("Set env variable KUSTO_DATABASE first!") | ||
} | ||
|
||
fn get_client_id() -> String { | ||
std::env::var("AZURE_CLIENT_ID").expect("Set env variable AZURE_CLIENT_ID first!") | ||
} | ||
|
||
fn get_client_secret() -> String { | ||
std::env::var("AZURE_CLIENT_SECRET").expect("Set env variable AZURE_CLIENT_SECRET first!") | ||
} | ||
|
||
fn get_tenant_id() -> String { | ||
std::env::var("AZURE_TENANT_ID").expect("Set env variable AZURE_TENANT_ID first!") | ||
} |
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 @@ | ||
find test -name "*.json" -exec bash -c 'jq . {} > {}.tmp && mv {}.tmp {}' \; |
15 changes: 15 additions & 0 deletions
15
test/transactions/data_create_query_delete_table/0_request.json
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 @@ | ||
{ | ||
"uri": "/v1/rest/mgmt", | ||
"method": "POST", | ||
"headers": { | ||
"accept": "application/json", | ||
"accept-encoding": "gzip", | ||
"authorization": "<<STRIPPED>>", | ||
"content-length": "86", | ||
"content-type": "application/json; charset=utf-8", | ||
"user-agent": "azsdk-rust-azure-kusto-data/0.1.0 (1.59.0; linux; x86_64)", | ||
"x-ms-client-version": "Kusto.Rust.Client:0.1.0", | ||
"x-ms-version": "2019-02-13" | ||
}, | ||
"body": "eyJkYiI6ImN0bmEiLCJjc2wiOiIuc2V0IEt1c3RvUnNUZXN0IDx8XG5sZXQgdGV4dD1cIkhlbGxvLCBXb3JsZCFcIjtcbnByaW50IHN0cj10ZXh0In0=" | ||
} |
14 changes: 14 additions & 0 deletions
14
test/transactions/data_create_query_delete_table/0_response.json
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,14 @@ | ||
{ | ||
"status": 200, | ||
"headers": { | ||
"content-type": "application/json; charset=UTF-8", | ||
"date": "Sat, 23 Apr 2022 23:01:55 GMT", | ||
"server": "Microsoft-HTTPAPI/2.0", | ||
"strict-transport-security": "max-age=15724800; includeSubDomains", | ||
"transfer-encoding": "chunked", | ||
"vary": "Accept-Encoding", | ||
"x-ms-activity-id": "8ed01694-6c7b-48a9-a38b-d31aace619b0", | ||
"x-ms-client-request-id": "unspecified;43c0cb94-5281-4ccf-89d5-98fcbb8d2214" | ||
}, | ||
"body": "eyJUYWJsZXMiOlt7IlRhYmxlTmFtZSI6IlRhYmxlXzAiLCJDb2x1bW5zIjpbeyJDb2x1bW5OYW1lIjoiRXh0ZW50SWQiLCJEYXRhVHlwZSI6Ikd1aWQiLCJDb2x1bW5UeXBlIjoiZ3VpZCJ9LHsiQ29sdW1uTmFtZSI6Ik9yaWdpbmFsU2l6ZSIsIkRhdGFUeXBlIjoiRG91YmxlIiwiQ29sdW1uVHlwZSI6InJlYWwifSx7IkNvbHVtbk5hbWUiOiJFeHRlbnRTaXplIiwiRGF0YVR5cGUiOiJEb3VibGUiLCJDb2x1bW5UeXBlIjoicmVhbCJ9LHsiQ29sdW1uTmFtZSI6IkNvbXByZXNzZWRTaXplIiwiRGF0YVR5cGUiOiJEb3VibGUiLCJDb2x1bW5UeXBlIjoicmVhbCJ9LHsiQ29sdW1uTmFtZSI6IkluZGV4U2l6ZSIsIkRhdGFUeXBlIjoiRG91YmxlIiwiQ29sdW1uVHlwZSI6InJlYWwifSx7IkNvbHVtbk5hbWUiOiJSb3dDb3VudCIsIkRhdGFUeXBlIjoiSW50NjQiLCJDb2x1bW5UeXBlIjoibG9uZyJ9XSwiUm93cyI6W1siNzA4MjhhODAtZmM0YS00MmNiLWI4ZDMtNGMzN2Y2MjM0MjczIiwyMS4wLDMzNS4wLDEyOC4wLDIwNy4wLDFdXX1dfQ==" | ||
} |
15 changes: 15 additions & 0 deletions
15
test/transactions/data_create_query_delete_table/1_request.json
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 @@ | ||
{ | ||
"uri": "/v1/rest/mgmt", | ||
"method": "POST", | ||
"headers": { | ||
"accept": "application/json", | ||
"accept-encoding": "gzip", | ||
"authorization": "<<STRIPPED>>", | ||
"content-length": "45", | ||
"content-type": "application/json; charset=utf-8", | ||
"user-agent": "azsdk-rust-azure-kusto-data/0.1.0 (1.59.0; linux; x86_64)", | ||
"x-ms-client-version": "Kusto.Rust.Client:0.1.0", | ||
"x-ms-version": "2019-02-13" | ||
}, | ||
"body": "eyJkYiI6ImN0bmEiLCJjc2wiOiIuZHJvcCB0YWJsZSBLdXN0b1JzVGVzdCJ9" | ||
} |
14 changes: 14 additions & 0 deletions
14
test/transactions/data_create_query_delete_table/1_response.json
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,14 @@ | ||
{ | ||
"status": 200, | ||
"headers": { | ||
"content-type": "application/json; charset=UTF-8", | ||
"date": "Sat, 23 Apr 2022 23:01:55 GMT", | ||
"server": "Microsoft-HTTPAPI/2.0", | ||
"strict-transport-security": "max-age=15724800; includeSubDomains", | ||
"transfer-encoding": "chunked", | ||
"vary": "Accept-Encoding", | ||
"x-ms-activity-id": "3fa85740-2a34-4fbb-b048-defd4483a2b5", | ||
"x-ms-client-request-id": "unspecified;c0407779-644b-49b2-a8ff-37ab1c327f06" | ||
}, | ||
"body": "eyJUYWJsZXMiOlt7IlRhYmxlTmFtZSI6IlRhYmxlXzAiLCJDb2x1bW5zIjpbeyJDb2x1bW5OYW1lIjoiVGFibGVOYW1lIiwiRGF0YVR5cGUiOiJTdHJpbmciLCJDb2x1bW5UeXBlIjoic3RyaW5nIn0seyJDb2x1bW5OYW1lIjoiRGF0YWJhc2VOYW1lIiwiRGF0YVR5cGUiOiJTdHJpbmciLCJDb2x1bW5UeXBlIjoic3RyaW5nIn0seyJDb2x1bW5OYW1lIjoiRm9sZGVyIiwiRGF0YVR5cGUiOiJTdHJpbmciLCJDb2x1bW5UeXBlIjoic3RyaW5nIn0seyJDb2x1bW5OYW1lIjoiRG9jU3RyaW5nIiwiRGF0YVR5cGUiOiJTdHJpbmciLCJDb2x1bW5UeXBlIjoic3RyaW5nIn1dLCJSb3dzIjpbXX1dfQ==" | ||
} |