mirror of
https://github.com/hanzoai/insights-rs.git
synced 2026-10-30 18:33:10 +00:00
60 lines
1.9 KiB
Rust
60 lines
1.9 KiB
Rust
#[cfg(all(feature = "e2e-test", feature = "async-client"))]
|
|
#[tokio::test]
|
|
async fn get_client_async() {
|
|
use dotenv::dotenv;
|
|
dotenv().ok(); // Load the .env file
|
|
|
|
// see https://us.insights.com/project/115809/ for the e2e project
|
|
use insights_rs::Event;
|
|
use std::collections::HashMap;
|
|
|
|
let api_key = match std::env::var("INSIGHTS_RS_E2E_TEST_API_KEY") {
|
|
Ok(key) if !key.is_empty() => key,
|
|
_ => {
|
|
eprintln!("Skipping e2e test: INSIGHTS_RS_E2E_TEST_API_KEY not set");
|
|
return;
|
|
}
|
|
};
|
|
let client = insights_rs::client(api_key.as_str()).await;
|
|
|
|
let mut child_map = HashMap::new();
|
|
child_map.insert("child_key1", "child_value1");
|
|
|
|
let mut event = Event::new("e2e test event", "1234");
|
|
event.insert_prop("key1", "value1").unwrap();
|
|
event.insert_prop("key2", vec!["a", "b"]).unwrap();
|
|
event.insert_prop("key3", child_map).unwrap();
|
|
|
|
client.capture(event).await.unwrap();
|
|
}
|
|
|
|
#[cfg(all(feature = "e2e-test", not(feature = "async-client")))]
|
|
#[test]
|
|
fn get_client_blocking() {
|
|
use dotenv::dotenv;
|
|
dotenv().ok(); // Load the .env file
|
|
|
|
// see https://us.insights.com/project/115809/ for the e2e project
|
|
use insights_rs::Event;
|
|
use std::collections::HashMap;
|
|
|
|
let api_key = match std::env::var("INSIGHTS_RS_E2E_TEST_API_KEY") {
|
|
Ok(key) if !key.is_empty() => key,
|
|
_ => {
|
|
eprintln!("Skipping e2e test: INSIGHTS_RS_E2E_TEST_API_KEY not set");
|
|
return;
|
|
}
|
|
};
|
|
let client = insights_rs::client(api_key.as_str());
|
|
|
|
let mut child_map = HashMap::new();
|
|
child_map.insert("child_key1", "child_value1");
|
|
|
|
let mut event = Event::new("e2e test event", "1234");
|
|
event.insert_prop("key1", "value1").unwrap();
|
|
event.insert_prop("key2", vec!["a", "b"]).unwrap();
|
|
event.insert_prop("key3", child_map).unwrap();
|
|
|
|
client.capture(event).unwrap();
|
|
}
|