Real e2e
This commit is contained in:
Родитель
f1832afd94
Коммит
0b417d3d68
|
@ -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="..."
|
||||
|
@ -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:
|
||||
|
|
|
@ -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,
|
||||
|
@ -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>,
|
||||
},
|
||||
|
@ -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,
|
||||
|
@ -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 {
|
||||
|
@ -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(),
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -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>,
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#![cfg(feature = "mock_transport_framework")]
|
||||
use arrow::datatypes::{DataType, Field, Schema, TimeUnit};
|
||||
use std::sync::Arc;
|
||||
mod setup;
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#![cfg(feature = "mock_transport_framework")]
|
||||
|
||||
use azure_kusto_data::prelude::*;
|
||||
use dotenv::dotenv;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче