Skip to content

Commit

Permalink
fix: 🔧 Public modules
Browse files Browse the repository at this point in the history
  • Loading branch information
fungiboletus committed Aug 13, 2024
1 parent 847b2cd commit 050edd1
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
mod batch_update;
mod client;
mod consolidation_function;
mod create;
mod errors;
mod fetch;
mod now;
mod parsers;
mod sanitisation;
pub mod batch_update;
pub mod client;
pub mod consolidation_function;
pub mod create;
pub mod errors;
pub mod fetch;
pub mod now;
pub mod parsers;
pub mod sanitisation;

pub use client::RRDCachedClient;
153 changes: 153 additions & 0 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
use rrdcached_client::{
batch_update::BatchUpdate,
consolidation_function::ConsolidationFunction,
create::{CreateArguments, CreateDataSource, CreateDataSourceType, CreateRoundRobinArchive},
now::now_timestamp,
RRDCachedClient,
};
use tokio::net::TcpStream;

#[tokio::test]
async fn test_ping_tcp() {
let mut client = RRDCachedClient::connect_tcp("localhost:42217")
.await
.unwrap();
client.ping().await.unwrap();
}

#[tokio::test]
async fn test_ping_unix() {
let mut client = RRDCachedClient::connect_unix("./rrdcached.sock")
.await
.unwrap();
client.ping().await.unwrap();
}

#[tokio::test]
async fn test_create() {
let mut client = RRDCachedClient::connect_tcp("localhost:42217")
.await
.unwrap();

client
.create(CreateArguments {
path: "integration-test-create".to_string(),
data_sources: vec![
CreateDataSource {
name: "ds1".to_string(),
minimum: None,
maximum: None,
heartbeat: 10,
serie_type: CreateDataSourceType::Gauge,
},
CreateDataSource {
name: "ds2".to_string(),
minimum: Some(0.0),
maximum: Some(100.0),
heartbeat: 10,
serie_type: CreateDataSourceType::Gauge,
},
],
round_robin_archives: vec![
CreateRoundRobinArchive {
consolidation_function: ConsolidationFunction::Average,
xfiles_factor: 0.5,
steps: 1,
rows: 10,
},
CreateRoundRobinArchive {
consolidation_function: ConsolidationFunction::Average,
xfiles_factor: 0.5,
steps: 10,
rows: 10,
},
],
start_timestamp: 1609459200,
step_seconds: 1,
})
.await
.unwrap();
}

async fn create_simple_rrd(client: &mut RRDCachedClient<TcpStream>, name: String) {
client
.create(CreateArguments {
path: name,
data_sources: vec![CreateDataSource {
name: "ds1".to_string(),
minimum: None,
maximum: None,
heartbeat: 10,
serie_type: CreateDataSourceType::Gauge,
}],
round_robin_archives: vec![CreateRoundRobinArchive {
consolidation_function: ConsolidationFunction::Average,
xfiles_factor: 0.5,
steps: 1,
rows: 100,
}],
start_timestamp: 1609459200,
step_seconds: 1,
})
.await
.unwrap();
}

#[tokio::test]
async fn test_update() {
let mut client = RRDCachedClient::connect_tcp("localhost:42217")
.await
.unwrap();

create_simple_rrd(&mut client, "test-integrations-update".to_string()).await;
client
.update_one("test-integrations-update", None, 4.2)
.await
.unwrap();
}

#[tokio::test]
async fn test_double_create() {
let mut client = RRDCachedClient::connect_tcp("localhost:42217")
.await
.unwrap();

create_simple_rrd(&mut client, "test-integrations-double-create".to_string()).await;
let timestamp_last = client
.last("test-integrations-double-create")
.await
.unwrap();
client
.update_one("test-integrations-double-create", None, 4.2)
.await
.unwrap();
let new_timestamp = client
.last("test-integrations-double-create")
.await
.unwrap();

assert!(new_timestamp > timestamp_last);

create_simple_rrd(&mut client, "test-integrations-double-create".to_string()).await;
let not_overwritten_timestamp = client
.last("test-integrations-double-create")
.await
.unwrap();
assert_eq!(not_overwritten_timestamp, new_timestamp);
}

#[tokio::test]
async fn test_batch() {
let mut client = RRDCachedClient::connect_tcp("localhost:42217")
.await
.unwrap();

create_simple_rrd(&mut client, "test-integrations-batch".to_string()).await;

let now = now_timestamp().unwrap();
let commands = vec![
BatchUpdate::new("test-integrations-batch", Some(now - 2), vec![1.0]).unwrap(),
BatchUpdate::new("test-integrations-batch", None, vec![2.0]).unwrap(),
];
client.batch(commands).await.unwrap();
}

0 comments on commit 050edd1

Please sign in to comment.