Skip to content

Commit

Permalink
feat: allow to create GstClient from Url
Browse files Browse the repository at this point in the history
  • Loading branch information
Serhii Khalymon authored and eirenik0 committed Jul 20, 2024
1 parent 3e46734 commit 6cf5178
Showing 1 changed file with 48 additions and 7 deletions.
55 changes: 48 additions & 7 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use url::Url;
#[derive(Debug, Clone)]
pub struct GstClient {
http_client: Client,
base_url: Url,
pub(crate) base_url: Url,
}

impl GstClient {
Expand Down Expand Up @@ -121,14 +121,55 @@ impl Default for GstClient {
}
}

impl From<Url> for GstClient {
fn from(url: Url) -> Self {
Self {
http_client: Client::new(),
base_url: url,
}
}
}

impl From<&Url> for GstClient {
fn from(url: &Url) -> Self {
Self {
http_client: Client::new(),
base_url: url.clone(),
}
}
}

#[cfg(test)]
mod spec {
use super::*;
const BASE_URL: &'static str = "http://10.211.55.4:5000";

fn expect_url() -> Url {
Url::parse(BASE_URL).unwrap()
}

#[test]
fn create_client_with_build() {
let client = GstClient::build(BASE_URL).unwrap();
assert_eq!(client.base_url, expect_url());

let client = GstClient::build(BASE_URL.to_string()).unwrap();
assert_eq!(client.base_url, expect_url());
}

#[test]
fn create_client_from() {
let url = expect_url();
let client = GstClient::from(&url);
assert_eq!(client.base_url, expect_url());

let client = GstClient::from(url);
assert_eq!(client.base_url, expect_url());
}

#[tokio::test]
async fn retrieve_pipelines() {
if let Ok(client) = GstClient::build(&BASE_URL) {
if let Ok(client) = GstClient::build(BASE_URL) {
let res = client.pipelines().await;
println!("{:?}", res);
assert!(res.is_ok());
Expand All @@ -137,7 +178,7 @@ mod spec {

#[tokio::test]
async fn retrieve_pipeline_graph() {
if let Ok(client) = GstClient::build(&BASE_URL) {
if let Ok(client) = GstClient::build(BASE_URL) {
let res = client.pipeline("test-pipeline").graph().await;
println!("{:?}", res);
assert!(res.is_ok());
Expand All @@ -146,23 +187,23 @@ mod spec {

#[tokio::test]
async fn retrieve_pipeline_elements() {
if let Ok(client) = GstClient::build(&BASE_URL) {
if let Ok(client) = GstClient::build(BASE_URL) {
let res = client.pipeline("test-pipeline").elements().await;
println!("{:?}", res);
assert!(res.is_ok());
};
}
#[tokio::test]
async fn retrieve_pipeline_properties() {
if let Ok(client) = GstClient::build(&BASE_URL) {
if let Ok(client) = GstClient::build(BASE_URL) {
let res = client.pipeline("test-pipeline").properties().await;
println!("{:?}", res);
assert!(res.is_ok());
};
}
#[tokio::test]
async fn retrieve_pipeline_element_property() {
if let Ok(client) = GstClient::build(&BASE_URL) {
if let Ok(client) = GstClient::build(BASE_URL) {
let res = client
.pipeline("test-pipeline")
.element("rtmp2src")
Expand All @@ -174,7 +215,7 @@ mod spec {
}
#[tokio::test]
async fn retrieve_pipeline_bus_read() {
if let Ok(client) = GstClient::build(&BASE_URL) {
if let Ok(client) = GstClient::build(BASE_URL) {
let res = client.pipeline("test-pipeline").bus().read().await;
println!("{:?}", res);
assert!(res.is_ok());
Expand Down

0 comments on commit 6cf5178

Please sign in to comment.