cargo fmt + clippy
All checks were successful
Build and test / check (push) Successful in 1m55s
Build and test / build (push) Successful in 1m59s
Build and test / test (push) Successful in 2m30s

This commit is contained in:
2024-04-30 02:13:57 +02:00
parent 7bcd3fc1ec
commit 3be7b2bda6
10 changed files with 134 additions and 138 deletions

View File

@@ -1,7 +1,7 @@
use std::panic;
use futures::{stream::StreamExt, SinkExt};
use mpvipc::{Mpv, MpvExt, MpvDataType, Property};
use mpvipc::{Mpv, MpvDataType, MpvExt, Property};
use serde_json::json;
use test_log::test;
use tokio::{net::UnixStream, task::JoinHandle};

View File

@@ -89,32 +89,27 @@ async fn test_get_property_simultaneous_requests() {
let mut framed = Framed::new(socket, LinesCodec::new());
while let Some(request) = framed.next().await {
match serde_json::from_str::<Value>(&request.unwrap()) {
Ok(json) => {
let property = json["command"][1].as_str().unwrap();
log::info!("Received request for property: {:?}", property);
match property {
"volume" => {
let response =
json!({ "data": 100.0, "request_id": 0, "error": "success" })
.to_string();
framed.send(response).await.unwrap();
}
"pause" => {
let response =
json!({ "data": true, "request_id": 0, "error": "success" })
.to_string();
framed.send(response).await.unwrap();
}
_ => {
let response =
json!({ "error": "property unavailable", "request_id": 0 })
.to_string();
framed.send(response).await.unwrap();
}
if let Ok(json) = serde_json::from_str::<Value>(&request.unwrap()) {
let property = json["command"][1].as_str().unwrap();
log::info!("Received request for property: {:?}", property);
match property {
"volume" => {
let response =
json!({ "data": 100.0, "request_id": 0, "error": "success" })
.to_string();
framed.send(response).await.unwrap();
}
"pause" => {
let response = json!({ "data": true, "request_id": 0, "error": "success" })
.to_string();
framed.send(response).await.unwrap();
}
_ => {
let response =
json!({ "error": "property unavailable", "request_id": 0 }).to_string();
framed.send(response).await.unwrap();
}
}
Err(_) => {}
}
}
@@ -136,7 +131,7 @@ async fn test_get_property_simultaneous_requests() {
loop {
tokio::time::sleep(Duration::from_millis(1)).await;
let paused: bool = mpv_clone_2.get_property("pause").await.unwrap();
assert_eq!(paused, true);
assert!(paused);
}
});

View File

@@ -79,9 +79,7 @@ async fn test_get_property_error() {
assert_eq!(
maybe_volume,
Err(Error(ErrorCode::MpvError(
"property not found".to_owned()
)))
Err(Error(ErrorCode::MpvError("property not found".to_owned())))
);
join_handle.await.unwrap().unwrap();
@@ -94,33 +92,29 @@ async fn test_set_property_simultaneous_requests() {
let mut framed = Framed::new(socket, LinesCodec::new());
while let Some(request) = framed.next().await {
match serde_json::from_str::<Value>(&request.unwrap()) {
Ok(json) => {
let property = json["command"][1].as_str().unwrap();
let value = &json["command"][2];
log::info!("Received set property command: {:?} => {:?}", property, value);
match property {
"volume" => {
let response =
json!({ "request_id": 0, "error": "success" })
.to_string();
framed.send(response).await.unwrap();
}
"pause" => {
let response =
json!({ "request_id": 0, "error": "success" })
.to_string();
framed.send(response).await.unwrap();
}
_ => {
let response =
json!({ "error":"property not found", "request_id": 0 })
.to_string();
framed.send(response).await.unwrap();
}
if let Ok(json) = serde_json::from_str::<Value>(&request.unwrap()) {
let property = json["command"][1].as_str().unwrap();
let value = &json["command"][2];
log::info!(
"Received set property command: {:?} => {:?}",
property,
value
);
match property {
"volume" => {
let response = json!({ "request_id": 0, "error": "success" }).to_string();
framed.send(response).await.unwrap();
}
"pause" => {
let response = json!({ "request_id": 0, "error": "success" }).to_string();
framed.send(response).await.unwrap();
}
_ => {
let response =
json!({ "error":"property not found", "request_id": 0 }).to_string();
framed.send(response).await.unwrap();
}
}
Err(_) => {}
}
}
@@ -153,9 +147,7 @@ async fn test_set_property_simultaneous_requests() {
let maybe_volume = mpv_clone_3.set_property("nonexistent", "a").await;
assert_eq!(
maybe_volume,
Err(Error(ErrorCode::MpvError(
"property not found".to_owned()
)))
Err(Error(ErrorCode::MpvError("property not found".to_owned())))
);
}
});