removed tracing/color-eyre and added thiserror

This commit is contained in:
Ishan Jain 2022-04-18 01:33:01 +05:30
parent 46d64ef491
commit 5cd027d271
9 changed files with 103 additions and 342 deletions

232
Cargo.lock generated
View File

@ -2,30 +2,6 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 3
[[package]]
name = "addr2line"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b"
dependencies = [
"gimli",
]
[[package]]
name = "adler"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "ansi_term"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
dependencies = [
"winapi",
]
[[package]] [[package]]
name = "async-stream" name = "async-stream"
version = "0.3.3" version = "0.3.3"
@ -53,21 +29,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "backtrace"
version = "0.3.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e121dee8023ce33ab248d9ce1493df03c3b38a659b240096fcbd7048ff9c31f"
dependencies = [
"addr2line",
"cc",
"cfg-if",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
]
[[package]] [[package]]
name = "base64" name = "base64"
version = "0.13.0" version = "0.13.0"
@ -104,33 +65,6 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "color-eyre"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ebf286c900a6d5867aeff75cfee3192857bb7f24b547d4f0df2ed6baa812c90"
dependencies = [
"backtrace",
"color-spantrace",
"eyre",
"indenter",
"once_cell",
"owo-colors",
"tracing-error",
]
[[package]]
name = "color-spantrace"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ba75b3d9449ecdccb27ecbc479fdc0b87fa2dd43d2f8298f9bf0e59aacc8dce"
dependencies = [
"once_cell",
"owo-colors",
"tracing-core",
"tracing-error",
]
[[package]] [[package]]
name = "core-foundation" name = "core-foundation"
version = "0.9.3" version = "0.9.3"
@ -156,16 +90,6 @@ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]]
name = "eyre"
version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c2b6b5a29c02cdc822728b7d7b8ae1bab3e3b05d44522770ddd49722eeac7eb"
dependencies = [
"indenter",
"once_cell",
]
[[package]] [[package]]
name = "fastrand" name = "fastrand"
version = "1.7.0" version = "1.7.0"
@ -295,12 +219,6 @@ dependencies = [
"slab", "slab",
] ]
[[package]]
name = "gimli"
version = "0.26.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4"
[[package]] [[package]]
name = "h2" name = "h2"
version = "0.3.13" version = "0.3.13"
@ -430,12 +348,6 @@ dependencies = [
"unicode-normalization", "unicode-normalization",
] ]
[[package]]
name = "indenter"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683"
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "1.8.1" version = "1.8.1"
@ -507,15 +419,6 @@ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]]
name = "matchers"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558"
dependencies = [
"regex-automata",
]
[[package]] [[package]]
name = "matches" name = "matches"
version = "0.1.9" version = "0.1.9"
@ -530,17 +433,17 @@ checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
[[package]] [[package]]
name = "mikrotik" name = "mikrotik"
version = "0.0.2" version = "0.0.3"
dependencies = [ dependencies = [
"base64", "base64",
"color-eyre",
"futures", "futures",
"reqwest", "reqwest",
"serde", "serde",
"serde_derive", "serde_derive",
"thiserror",
"tokio", "tokio",
"tokio-test", "tokio-test",
"tracing-subscriber", "url",
] ]
[[package]] [[package]]
@ -549,16 +452,6 @@ version = "0.3.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d"
[[package]]
name = "miniz_oxide"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b"
dependencies = [
"adler",
"autocfg",
]
[[package]] [[package]]
name = "mio" name = "mio"
version = "0.8.2" version = "0.8.2"
@ -619,15 +512,6 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "object"
version = "0.27.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67ac1d3f9a1d3616fd9a60c8d74296f22406a238b6a72f5cc1e6f314df4ffbf9"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.10.0" version = "1.10.0"
@ -667,12 +551,6 @@ dependencies = [
"vcpkg", "vcpkg",
] ]
[[package]]
name = "owo-colors"
version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e72e30578e0d0993c8ae20823dd9cff2bc5517d2f586a8aef462a581e8a03eb"
[[package]] [[package]]
name = "parking_lot" name = "parking_lot"
version = "0.12.0" version = "0.12.0"
@ -747,30 +625,6 @@ dependencies = [
"bitflags", "bitflags",
] ]
[[package]]
name = "regex"
version = "1.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a11647b6b25ff05a515cb92c365cec08801e83423a235b51e231e1808747286"
dependencies = [
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
dependencies = [
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.6.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
[[package]] [[package]]
name = "remove_dir_all" name = "remove_dir_all"
version = "0.5.3" version = "0.5.3"
@ -836,12 +690,6 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "rustc-demangle"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342"
[[package]] [[package]]
name = "rustls" name = "rustls"
version = "0.20.4" version = "0.20.4"
@ -961,15 +809,6 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "sharded-slab"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31"
dependencies = [
"lazy_static",
]
[[package]] [[package]]
name = "signal-hook-registry" name = "signal-hook-registry"
version = "1.4.0" version = "1.4.0"
@ -1033,12 +872,23 @@ dependencies = [
] ]
[[package]] [[package]]
name = "thread_local" name = "thiserror"
version = "1.1.4" version = "1.0.30"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417"
dependencies = [ dependencies = [
"once_cell", "thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b"
dependencies = [
"proc-macro2",
"quote",
"syn",
] ]
[[package]] [[package]]
@ -1182,46 +1032,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f54c8ca710e81886d498c2fd3331b56c93aa248d49de2222ad2742247c60072f" checksum = "f54c8ca710e81886d498c2fd3331b56c93aa248d49de2222ad2742247c60072f"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
"valuable",
]
[[package]]
name = "tracing-error"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e"
dependencies = [
"tracing",
"tracing-subscriber",
]
[[package]]
name = "tracing-log"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6923477a48e41c1951f1999ef8bb5a3023eb723ceadafe78ffb65dc366761e3"
dependencies = [
"lazy_static",
"log",
"tracing-core",
]
[[package]]
name = "tracing-subscriber"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bc28f93baff38037f64e6f43d34cfa1605f27a49c34e8a04c5e78b0babf2596"
dependencies = [
"ansi_term",
"lazy_static",
"matchers",
"regex",
"sharded-slab",
"smallvec",
"thread_local",
"tracing",
"tracing-core",
"tracing-log",
] ]
[[package]] [[package]]
@ -1269,12 +1079,6 @@ dependencies = [
"percent-encoding", "percent-encoding",
] ]
[[package]]
name = "valuable"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]] [[package]]
name = "vcpkg" name = "vcpkg"
version = "0.2.15" version = "0.2.15"

View File

@ -4,18 +4,17 @@ version = "0.0.3"
edition = "2021" edition = "2021"
description = "REST API Wrapper for Mikrotik API" description = "REST API Wrapper for Mikrotik API"
license = "MIT" license = "MIT"
license-file = "LICENSE"
[dev-dependencies] [dev-dependencies]
tokio-test = "0.4.2" tokio-test = "0.4.2"
tracing-subscriber = { version = "0.3.11", features = ["env-filter"] }
[dependencies] [dependencies]
base64 = "0.13.0" base64 = "0.13.0"
color-eyre = "0.6.1"
futures = "0.3.17" futures = "0.3.17"
reqwest = { version = "0.11.4", features = ["rustls-tls", "serde_json", "json"] } reqwest = { version = "0.11.4", features = ["rustls-tls", "serde_json", "json"] }
serde = { version = "1.0.130", features = ["derive"] } serde = { version = "1.0.130", features = ["derive"] }
serde_derive = "1.0.136" serde_derive = "1.0.136"
thiserror = "1.0.30"
tokio = { version = "1.10.1", features = ["full"] } tokio = { version = "1.10.1", features = ["full"] }
url = "2.2.2"

View File

@ -1,8 +1,8 @@
use color_eyre::Report;
use reqwest::{ use reqwest::{
header::{HeaderMap, HeaderValue}, header::{HeaderMap, HeaderValue},
Request, Url, Request, Url,
}; };
use thiserror::Error;
pub struct Client { pub struct Client {
pub client: reqwest::Client, pub client: reqwest::Client,
@ -17,7 +17,7 @@ impl Client {
username: String, username: String,
password: String, password: String,
self_signed_cert: bool, self_signed_cert: bool,
) -> Result<Self, Report> { ) -> Result<Self, ClientError> {
let value = format!("{}:{}", username, password); let value = format!("{}:{}", username, password);
let value = base64::encode(value); let value = base64::encode(value);
@ -49,3 +49,15 @@ impl Client {
self.client.execute(r).await self.client.execute(r).await
} }
} }
#[derive(Debug, Error)]
pub enum ClientError {
#[error(transparent)]
InvalidHeaderValue(#[from] reqwest::header::InvalidHeaderValue),
#[error(transparent)]
UrlError(#[from] url::ParseError),
#[error(transparent)]
ReqwestError(#[from] reqwest::Error),
}

View File

@ -1,8 +1,17 @@
use crate::{interface::types::Interface, Client}; use crate::{interface::types::Interface, Client};
use color_eyre::Report;
use reqwest::{Method, Request}; use reqwest::{Method, Request};
use thiserror::Error;
pub async fn list(client: &mut Client) -> Result<Vec<Interface>, Report> { #[derive(Error, Debug)]
pub enum InterfaceError {
#[error(transparent)]
UrlError(#[from] url::ParseError),
#[error(transparent)]
ReqwestError(#[from] reqwest::Error),
}
pub async fn list(client: &mut Client) -> Result<Vec<Interface>, InterfaceError> {
let url = client.base_url.clone(); let url = client.base_url.clone();
let url = url.join(super::BASE)?; let url = url.join(super::BASE)?;
@ -13,7 +22,7 @@ pub async fn list(client: &mut Client) -> Result<Vec<Interface>, Report> {
Ok(response) Ok(response)
} }
pub async fn get(client: &mut Client, ifid: &str) -> Result<Interface, Report> { pub async fn get(client: &mut Client, ifid: &str) -> Result<Interface, InterfaceError> {
let url = client.base_url.clone(); let url = client.base_url.clone();
let url = url.join(&format!("{}/{}", super::BASE, ifid))?; let url = url.join(&format!("{}/{}", super::BASE, ifid))?;

View File

@ -2,10 +2,10 @@ use crate::{
ip::types::{DhcpServer, Lease, Network}, ip::types::{DhcpServer, Lease, Network},
Client, Client,
}; };
use color_eyre::Report;
use reqwest::{Method, Request}; use reqwest::{Method, Request};
use thiserror::Error;
pub async fn list(client: &mut Client) -> Result<Vec<DhcpServer>, Report> { pub async fn list(client: &mut Client) -> Result<Vec<DhcpServer>, DhcpServerError> {
let url = client.base_url.clone(); let url = client.base_url.clone();
let url = url.join(&format!("{}/dhcp-server", super::BASE))?; let url = url.join(&format!("{}/dhcp-server", super::BASE))?;
let req = Request::new(Method::GET, url); let req = Request::new(Method::GET, url);
@ -14,7 +14,7 @@ pub async fn list(client: &mut Client) -> Result<Vec<DhcpServer>, Report> {
Ok(response) Ok(response)
} }
pub async fn get(client: &mut Client, dhcp_server_id: &str) -> Result<DhcpServer, Report> { pub async fn get(client: &mut Client, dhcp_server_id: &str) -> Result<DhcpServer, DhcpServerError> {
let url = client.base_url.clone(); let url = client.base_url.clone();
let url = url.join(&format!("{}/dhcp-server/{}", super::BASE, dhcp_server_id))?; let url = url.join(&format!("{}/dhcp-server/{}", super::BASE, dhcp_server_id))?;
let req = Request::new(Method::GET, url); let req = Request::new(Method::GET, url);
@ -23,7 +23,7 @@ pub async fn get(client: &mut Client, dhcp_server_id: &str) -> Result<DhcpServer
Ok(response) Ok(response)
} }
pub async fn list_network(client: &mut Client) -> Result<Vec<Network>, Report> { pub async fn list_network(client: &mut Client) -> Result<Vec<Network>, DhcpServerError> {
let url = client.base_url.clone(); let url = client.base_url.clone();
let url = url.join(&format!("{}/dhcp-server/network", super::BASE))?; let url = url.join(&format!("{}/dhcp-server/network", super::BASE))?;
let req = Request::new(Method::GET, url); let req = Request::new(Method::GET, url);
@ -32,7 +32,7 @@ pub async fn list_network(client: &mut Client) -> Result<Vec<Network>, Report> {
Ok(response) Ok(response)
} }
pub async fn get_network(client: &mut Client, nid: &str) -> Result<Network, Report> { pub async fn get_network(client: &mut Client, nid: &str) -> Result<Network, DhcpServerError> {
let url = client.base_url.clone(); let url = client.base_url.clone();
let url = url.join(&format!("{}/dhcp-server/network/{}", super::BASE, nid))?; let url = url.join(&format!("{}/dhcp-server/network/{}", super::BASE, nid))?;
let req = Request::new(Method::GET, url); let req = Request::new(Method::GET, url);
@ -41,7 +41,7 @@ pub async fn get_network(client: &mut Client, nid: &str) -> Result<Network, Repo
Ok(response) Ok(response)
} }
pub async fn list_leases(client: &mut Client) -> Result<Vec<Lease>, Report> { pub async fn list_leases(client: &mut Client) -> Result<Vec<Lease>, DhcpServerError> {
let url = client.base_url.clone(); let url = client.base_url.clone();
let url = url.join(&format!("{}/dhcp-server/lease", super::BASE))?; let url = url.join(&format!("{}/dhcp-server/lease", super::BASE))?;
let req = Request::new(Method::GET, url); let req = Request::new(Method::GET, url);
@ -50,7 +50,7 @@ pub async fn list_leases(client: &mut Client) -> Result<Vec<Lease>, Report> {
Ok(response) Ok(response)
} }
pub async fn get_lease(client: &mut Client, lease_id: &str) -> Result<Lease, Report> { pub async fn get_lease(client: &mut Client, lease_id: &str) -> Result<Lease, DhcpServerError> {
let url = client.base_url.clone(); let url = client.base_url.clone();
let url = url.join(&format!("{}/dhcp-server/lease/{}", super::BASE, lease_id))?; let url = url.join(&format!("{}/dhcp-server/lease/{}", super::BASE, lease_id))?;
let req = Request::new(Method::GET, url); let req = Request::new(Method::GET, url);
@ -58,3 +58,12 @@ pub async fn get_lease(client: &mut Client, lease_id: &str) -> Result<Lease, Rep
Ok(response) Ok(response)
} }
#[derive(Debug, Error)]
pub enum DhcpServerError {
#[error(transparent)]
UrlError(#[from] url::ParseError),
#[error(transparent)]
ReqwestError(#[from] reqwest::Error),
}

View File

@ -1,8 +1,17 @@
use crate::{system::types::Health, Client}; use crate::{system::types::Health, Client};
use color_eyre::Report;
use reqwest::{Method, Request}; use reqwest::{Method, Request};
use thiserror::Error;
pub async fn health(client: &mut Client) -> Result<Vec<Health>, Report> { #[derive(Error, Debug)]
pub enum HealthError {
#[error(transparent)]
UrlError(#[from] url::ParseError),
#[error(transparent)]
ReqwestError(#[from] reqwest::Error),
}
pub async fn health(client: &mut Client) -> Result<Vec<Health>, HealthError> {
let url = client.base_url.clone(); let url = client.base_url.clone();
let url = url.join(&format!("{}/health", super::BASE))?; let url = url.join(&format!("{}/health", super::BASE))?;

View File

@ -1,36 +1,11 @@
use color_eyre::Report; use mikrotik::{interface::InterfaceError, Client};
use mikrotik::Client;
use reqwest::Url; use reqwest::Url;
use std::sync::Once;
use tracing_subscriber::EnvFilter;
static INIT: Once = Once::new();
fn setup() -> Result<(), Report> {
INIT.call_once(|| {
if std::env::var("RUST_LIB_BACKTRACE").is_err() {
std::env::set_var("RUST_LIB_BACKTRACE", "1")
}
color_eyre::install();
if std::env::var("RUST_LOG").is_err() {
std::env::set_var("RUST_LOG", "info");
}
tracing_subscriber::fmt::fmt()
.with_env_filter(EnvFilter::from_default_env())
.init();
});
Ok(())
}
#[tokio::test] #[tokio::test]
async fn list_interfaces() -> Result<(), Report> { async fn list_interfaces() -> Result<(), InterfaceError> {
setup()?;
let base = Url::parse("https://10.0.10.1")?; let base = Url::parse("https://10.0.10.1")?;
let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)?; let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)
.expect("error in creating client");
let response = mikrotik::interface::list(&mut client).await?; let response = mikrotik::interface::list(&mut client).await?;
@ -40,11 +15,10 @@ async fn list_interfaces() -> Result<(), Report> {
} }
#[tokio::test] #[tokio::test]
async fn get_interface() -> Result<(), Report> { async fn get_interface() -> Result<(), InterfaceError> {
setup()?;
let base = Url::parse("https://10.0.10.1")?; let base = Url::parse("https://10.0.10.1")?;
let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)?; let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)
.expect("error in creating client");
let response = mikrotik::interface::get(&mut client, "ether5").await?; let response = mikrotik::interface::get(&mut client, "ether5").await?;

View File

@ -1,36 +1,11 @@
use color_eyre::Report; use mikrotik::{ip::dhcp_server::DhcpServerError, Client};
use mikrotik::Client;
use reqwest::Url; use reqwest::Url;
use std::sync::Once;
use tracing_subscriber::EnvFilter;
static INIT: Once = Once::new();
fn setup() -> Result<(), Report> {
INIT.call_once(|| {
if std::env::var("RUST_LIB_BACKTRACE").is_err() {
std::env::set_var("RUST_LIB_BACKTRACE", "1")
}
color_eyre::install();
if std::env::var("RUST_LOG").is_err() {
std::env::set_var("RUST_LOG", "info");
}
tracing_subscriber::fmt::fmt()
.with_env_filter(EnvFilter::from_default_env())
.init();
});
Ok(())
}
#[tokio::test] #[tokio::test]
async fn list_dhcp_servers() -> Result<(), Report> { async fn list_dhcp_servers() -> Result<(), DhcpServerError> {
setup()?;
let base = Url::parse("https://10.0.10.1")?; let base = Url::parse("https://10.0.10.1")?;
let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)?; let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)
.expect("error in creating client");
let response = mikrotik::ip::dhcp_server::list(&mut client).await?; let response = mikrotik::ip::dhcp_server::list(&mut client).await?;
@ -40,11 +15,10 @@ async fn list_dhcp_servers() -> Result<(), Report> {
} }
#[tokio::test] #[tokio::test]
async fn get_dhcp_server() -> Result<(), Report> { async fn get_dhcp_server() -> Result<(), DhcpServerError> {
setup()?;
let base = Url::parse("https://10.0.10.1")?; let base = Url::parse("https://10.0.10.1")?;
let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)?; let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)
.expect("error in creating client");
let response = mikrotik::ip::dhcp_server::get(&mut client, "vlan-150").await?; let response = mikrotik::ip::dhcp_server::get(&mut client, "vlan-150").await?;
@ -54,11 +28,10 @@ async fn get_dhcp_server() -> Result<(), Report> {
} }
#[tokio::test] #[tokio::test]
async fn list_network() -> Result<(), Report> { async fn list_network() -> Result<(), DhcpServerError> {
setup()?;
let base = Url::parse("https://10.0.10.1")?; let base = Url::parse("https://10.0.10.1")?;
let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)?; let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)
.expect("error in creating client");
let response = mikrotik::ip::dhcp_server::list_network(&mut client).await?; let response = mikrotik::ip::dhcp_server::list_network(&mut client).await?;
@ -68,11 +41,10 @@ async fn list_network() -> Result<(), Report> {
} }
#[tokio::test] #[tokio::test]
async fn get_network() -> Result<(), Report> { async fn get_network() -> Result<(), DhcpServerError> {
setup()?;
let base = Url::parse("https://10.0.10.1")?; let base = Url::parse("https://10.0.10.1")?;
let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)?; let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)
.expect("error in creating client");
let response = mikrotik::ip::dhcp_server::list_network(&mut client).await?; let response = mikrotik::ip::dhcp_server::list_network(&mut client).await?;
@ -84,11 +56,10 @@ async fn get_network() -> Result<(), Report> {
} }
#[tokio::test] #[tokio::test]
async fn list_leases() -> Result<(), Report> { async fn list_leases() -> Result<(), DhcpServerError> {
setup()?;
let base = Url::parse("https://10.0.10.1")?; let base = Url::parse("https://10.0.10.1")?;
let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)?; let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)
.expect("error in creating client");
let response = mikrotik::ip::dhcp_server::list_leases(&mut client).await?; let response = mikrotik::ip::dhcp_server::list_leases(&mut client).await?;
@ -98,11 +69,10 @@ async fn list_leases() -> Result<(), Report> {
} }
#[tokio::test] #[tokio::test]
async fn get_lease() -> Result<(), Report> { async fn get_lease() -> Result<(), DhcpServerError> {
setup()?;
let base = Url::parse("https://10.0.10.1")?; let base = Url::parse("https://10.0.10.1")?;
let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)?; let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)
.expect("error in creating client");
let response = mikrotik::ip::dhcp_server::list_leases(&mut client).await?; let response = mikrotik::ip::dhcp_server::list_leases(&mut client).await?;

View File

@ -1,36 +1,11 @@
use color_eyre::Report; use mikrotik::{system::HealthError, Client};
use mikrotik::Client;
use reqwest::Url; use reqwest::Url;
use std::sync::Once;
use tracing_subscriber::EnvFilter;
static INIT: Once = Once::new();
fn setup() -> Result<(), Report> {
INIT.call_once(|| {
if std::env::var("RUST_LIB_BACKTRACE").is_err() {
std::env::set_var("RUST_LIB_BACKTRACE", "1")
}
color_eyre::install();
if std::env::var("RUST_LOG").is_err() {
std::env::set_var("RUST_LOG", "info");
}
tracing_subscriber::fmt::fmt()
.with_env_filter(EnvFilter::from_default_env())
.init();
});
Ok(())
}
#[tokio::test] #[tokio::test]
async fn health() -> Result<(), Report> { async fn health() -> Result<(), HealthError> {
setup()?;
let base = Url::parse("https://10.0.10.1")?; let base = Url::parse("https://10.0.10.1")?;
let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)?; let mut client = Client::new(base, "admin".to_string(), "ifd783far".to_string(), true)
.expect("error in creating client");
let response = mikrotik::system::health(&mut client).await?; let response = mikrotik::system::health(&mut client).await?;