Skip to content

Commit

Permalink
Real e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
AsafMah committed Aug 17, 2022
1 parent f1832af commit 0b417d3
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 35 deletions.
25 changes: 1 addition & 24 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,7 @@ follow the instructions provided in [Microsoft Azure Projects Contribution Guide

## Building and Testing

This project uses the [mock_transport_framework](https://github.com/Azure/azure-sdk-for-rust/blob/main/docs/mock_transport.md)
from the unofficial azure Rust SDKs. The main idea is to record interactions with external services (Kusto) locally, and replay
the responses in CI/CD and for normal testing. This is particularly useful for end to end tests.

To execute tests against recorded responses run:

```bash
cargo test --features=mock_transport_framework
```

> Using `cargo test` will also work, but omit all tests requiring the mock_transport_framework
To record new transactions, first place a `.env` file (omitted by `.gitignore`) in the repository root
To fully test the end-to-end functionality, you will need to provide the following environment variables for your service principal and cluster:

```toml
AZURE_CLIENT_ID="..."
Expand All @@ -29,17 +17,6 @@ KUSTO_DATABASE="..."

> The provided service principal needs to be able to `create` and `drop` tables in the specified database
Then execute tests in `RECORD` mode:

```bash
TESTING_MODE=RECORD cargo test --features=mock_transport_framework
```

> While all credentials and identifiable urls are stripped from recordings, the used database name, the query
> and responses are committed to source control. So make sure no sensitive data is contained therein. Care
> should also be taken to reduce the information about DB internals returned from a query - especially
> when using control commands.
## Style

We use `fmt` and `clippy` for formatting and linting:
Expand Down
13 changes: 9 additions & 4 deletions azure-kusto-data/src/connection_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ use once_cell::sync::Lazy;

use crate::error::ConnectionStringError;

/// Function that handles the device code flow.
pub type DeviceCodeFunction = Arc<dyn Fn(&str) -> String + Send + Sync>;
/// Function that returns a token.
pub type TokenCallbackFunction = Arc<dyn Fn(&str) -> String + Send + Sync>;

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
enum ConnectionStringKey {
DataSource,
Expand Down Expand Up @@ -186,7 +191,7 @@ pub enum ConnectionStringAuth {
/// Token callback - uses a user provided callback that accepts the resource and returns a token in order to authenticate.
TokenCallback {
/// A callback that accepts the resource id and returns a token in order to authenticate.
token_callback: Arc<dyn Fn(&str) -> String + Send + Sync>,
token_callback: TokenCallbackFunction,
/// The amount of time before calling the token callback again.
time_to_live: Option<Duration>,
},
Expand Down Expand Up @@ -220,7 +225,7 @@ pub enum ConnectionStringAuth {
/// Device code - Gives the user a device code that they have to use in order to authenticate.
DeviceCode {
/// Callback to activate the device code flow. If not given, will use the default of azure identity.
callback: Option<Arc<dyn Fn(&str) -> String + Send + Sync>>,
callback: Option<DeviceCodeFunction>,
},
/// Interactive - Gives the user an interactive prompt to authenticate.
InteractiveLogin,
Expand Down Expand Up @@ -714,7 +719,7 @@ impl ConnectionString {
#[must_use]
pub fn with_token_callback_auth(
data_source: impl Into<String>,
token_callback: Arc<dyn Fn(&str) -> String + Send + Sync>,
token_callback: TokenCallbackFunction,
time_to_live: Option<Duration>,
) -> Self {
Self {
Expand Down Expand Up @@ -860,7 +865,7 @@ impl ConnectionString {
#[must_use]
pub fn with_device_code_auth(
data_source: impl Into<String>,
callback: Option<Arc<dyn Fn(&str) -> String + Send + Sync>>,
callback: Option<DeviceCodeFunction>,
) -> Self {
Self {
data_source: data_source.into(),
Expand Down
4 changes: 2 additions & 2 deletions azure-kusto-data/src/credentials.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Custom credentials for Azure Data Explorer.
use crate::connection_string::TokenCallbackFunction;
use azure_core::auth::{AccessToken, TokenCredential, TokenResponse};
use std::sync::Arc;
use std::time::Duration;
use time::OffsetDateTime;

Expand All @@ -24,7 +24,7 @@ impl TokenCredential for ConstTokenCredential {

/// Uses a user provided callback that accepts the resource and returns a token in order to authenticate.
pub struct CallbackTokenCredential {
pub(crate) token_callback: Arc<dyn Fn(&str) -> String + Send + Sync>,
pub(crate) token_callback: TokenCallbackFunction,
pub(crate) time_to_live: Option<Duration>,
}

Expand Down
2 changes: 1 addition & 1 deletion azure-kusto-data/src/operations/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ impl KustoResponseDataSetV2 {
}
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
#[serde(rename_all = "PascalCase")]
/// The header of a Kusto response dataset for v1. Contains a list of tables.
pub struct KustoResponseDataSetV1 {
Expand Down
4 changes: 3 additions & 1 deletion azure-kusto-data/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
//! ```
pub use crate::client::{KustoClient, KustoClientOptions, QueryKind};
pub use crate::connection_string::{ConnectionString, ConnectionStringAuth};
pub use crate::connection_string::{
ConnectionString, ConnectionStringAuth, DeviceCodeFunction, TokenCallbackFunction,
};
pub use crate::error::Error;
pub use crate::models::{DataTable, V2QueryResult};
pub use crate::operations::query::{KustoResponse, KustoResponseDataSetV1, KustoResponseDataSetV2};
Expand Down
1 change: 0 additions & 1 deletion azure-kusto-data/tests/arrow.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![cfg(feature = "mock_transport_framework")]
use arrow::datatypes::{DataType, Field, Schema, TimeUnit};
use std::sync::Arc;
mod setup;
Expand Down
2 changes: 0 additions & 2 deletions azure-kusto-data/tests/setup.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![cfg(feature = "mock_transport_framework")]

use azure_kusto_data::prelude::*;
use dotenv::dotenv;

Expand Down

0 comments on commit 0b417d3

Please sign in to comment.