Linter suggestions
This commit is contained in:
parent
f5a2eed423
commit
d41e837561
10 changed files with 33 additions and 66 deletions
src
|
@ -9,7 +9,6 @@ fn apply_saves_misc_settings() {
|
|||
settings: Some(settings::NewSettings {
|
||||
album_art_pattern: Some("🖼️\\.jpg".into()),
|
||||
reindex_every_n_seconds: Some(100),
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
};
|
||||
|
@ -18,11 +17,11 @@ fn apply_saves_misc_settings() {
|
|||
let settings = ctx.settings_manager.read().unwrap();
|
||||
let new_settings = new_config.settings.unwrap();
|
||||
assert_eq!(
|
||||
settings.album_art_pattern,
|
||||
settings.index_album_art_pattern,
|
||||
new_settings.album_art_pattern.unwrap()
|
||||
);
|
||||
assert_eq!(
|
||||
settings.reindex_every_n_seconds,
|
||||
settings.index_sleep_duration_seconds,
|
||||
new_settings.reindex_every_n_seconds.unwrap()
|
||||
);
|
||||
}
|
||||
|
|
|
@ -211,15 +211,12 @@ fn album_art_pattern_is_case_insensitive() {
|
|||
.mount(TEST_MOUNT_NAME, "test-data/small-collection")
|
||||
.build();
|
||||
|
||||
let patterns = vec!["folder", "FOLDER"]
|
||||
.iter()
|
||||
.map(|s| s.to_string())
|
||||
.collect::<Vec<_>>();
|
||||
let patterns = vec!["folder", "FOLDER"];
|
||||
|
||||
for pattern in patterns.into_iter() {
|
||||
ctx.settings_manager
|
||||
.amend(&settings::NewSettings {
|
||||
album_art_pattern: Some(pattern),
|
||||
album_art_pattern: Some(pattern.to_owned()),
|
||||
..Default::default()
|
||||
})
|
||||
.unwrap();
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use anyhow::*;
|
||||
use rustfm_scrobble::{Scrobble, Scrobbler};
|
||||
use serde::Deserialize;
|
||||
use std::path::Path;
|
||||
use user::AuthToken;
|
||||
|
||||
|
@ -9,37 +8,6 @@ use crate::app::{index::Index, user};
|
|||
const LASTFM_API_KEY: &str = "02b96c939a2b451c31dfd67add1f696e";
|
||||
const LASTFM_API_SECRET: &str = "0f25a80ceef4b470b5cb97d99d4b3420";
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct AuthResponseSessionName {
|
||||
#[serde(rename = "$value")]
|
||||
pub body: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct AuthResponseSessionKey {
|
||||
#[serde(rename = "$value")]
|
||||
pub body: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct AuthResponseSessionSubscriber {
|
||||
#[serde(rename = "$value")]
|
||||
pub body: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct AuthResponseSession {
|
||||
pub name: AuthResponseSessionName,
|
||||
pub key: AuthResponseSessionKey,
|
||||
pub subscriber: AuthResponseSessionSubscriber,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct AuthResponse {
|
||||
pub status: String,
|
||||
pub session: AuthResponseSession,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Manager {
|
||||
index: Index,
|
||||
|
|
|
@ -61,17 +61,15 @@ impl Manager {
|
|||
}
|
||||
|
||||
pub fn read(&self) -> Result<Settings, Error> {
|
||||
use self::misc_settings::dsl::*;
|
||||
let mut connection = self.db.connect()?;
|
||||
|
||||
let misc: MiscSettings = misc_settings::table
|
||||
let settings: Settings = misc_settings
|
||||
.select((index_sleep_duration_seconds, index_album_art_pattern))
|
||||
.get_result(&mut connection)
|
||||
.map_err(|_| Error::Unspecified)?;
|
||||
|
||||
Ok(Settings {
|
||||
auth_secret: misc.auth_secret,
|
||||
album_art_pattern: misc.index_album_art_pattern,
|
||||
reindex_every_n_seconds: misc.index_sleep_duration_seconds,
|
||||
})
|
||||
Ok(settings)
|
||||
}
|
||||
|
||||
pub fn amend(&self, new_settings: &NewSettings) -> Result<(), Error> {
|
||||
|
|
|
@ -12,18 +12,9 @@ pub struct AuthSecret {
|
|||
}
|
||||
|
||||
#[derive(Debug, Queryable)]
|
||||
struct MiscSettings {
|
||||
id: i32,
|
||||
auth_secret: Vec<u8>,
|
||||
index_sleep_duration_seconds: i32,
|
||||
index_album_art_pattern: String,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Settings {
|
||||
auth_secret: Vec<u8>,
|
||||
pub reindex_every_n_seconds: i32,
|
||||
pub album_art_pattern: String,
|
||||
pub index_sleep_duration_seconds: i32,
|
||||
pub index_album_art_pattern: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize)]
|
||||
|
|
|
@ -228,8 +228,8 @@ pub struct Settings {
|
|||
impl From<settings::Settings> for Settings {
|
||||
fn from(s: settings::Settings) -> Self {
|
||||
Self {
|
||||
album_art_pattern: s.album_art_pattern,
|
||||
reindex_every_n_seconds: s.reindex_every_n_seconds,
|
||||
album_art_pattern: s.index_album_art_pattern,
|
||||
reindex_every_n_seconds: s.index_sleep_duration_seconds,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ fn login_golden_path() {
|
|||
|
||||
let authorization = response.body();
|
||||
assert_eq!(authorization.username, TEST_USERNAME);
|
||||
assert_eq!(authorization.is_admin, false);
|
||||
assert!(!authorization.is_admin);
|
||||
assert!(!authorization.token.is_empty());
|
||||
|
||||
validate_added_cookies(&response);
|
||||
|
|
|
@ -93,7 +93,7 @@ pub trait TestService {
|
|||
let browse_request = protocol::browse(Path::new(""));
|
||||
let response = self.fetch_json::<(), Vec<index::CollectionFile>>(&browse_request);
|
||||
let entries = response.body();
|
||||
if entries.len() > 0 {
|
||||
if !entries.is_empty() {
|
||||
break;
|
||||
}
|
||||
std::thread::sleep(Duration::from_secs(1));
|
||||
|
@ -103,7 +103,7 @@ pub trait TestService {
|
|||
let flatten_request = protocol::flatten(Path::new(""));
|
||||
let response = self.fetch_json::<_, Vec<index::Song>>(&flatten_request);
|
||||
let entries = response.body();
|
||||
if entries.len() > 0 {
|
||||
if !entries.is_empty() {
|
||||
break;
|
||||
}
|
||||
std::thread::sleep(Duration::from_secs(1));
|
||||
|
@ -112,7 +112,7 @@ pub trait TestService {
|
|||
}
|
||||
|
||||
fn add_trailing_slash<T>(request: &mut Request<T>) {
|
||||
*request.uri_mut() = (request.uri().to_string().trim_end_matches("/").to_string() + "/")
|
||||
*request.uri_mut() = (request.uri().to_string().trim_end_matches('/').to_string() + "/")
|
||||
.parse()
|
||||
.unwrap();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use http::StatusCode;
|
||||
|
||||
use crate::service::dto;
|
||||
use crate::service::dto::{self, Settings};
|
||||
use crate::service::test::{protocol, ServiceType, TestService};
|
||||
use crate::test_name;
|
||||
|
||||
|
@ -61,7 +61,21 @@ fn put_settings_golden_path() {
|
|||
service.complete_initial_setup();
|
||||
service.login_admin();
|
||||
|
||||
let request = protocol::put_settings(dto::NewSettings::default());
|
||||
let request = protocol::put_settings(dto::NewSettings {
|
||||
album_art_pattern: Some("test_pattern".to_owned()),
|
||||
reindex_every_n_seconds: Some(31),
|
||||
});
|
||||
let response = service.fetch(&request);
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
|
||||
let request = protocol::get_settings();
|
||||
let response = service.fetch_json::<_, dto::Settings>(&request);
|
||||
let settings = response.body();
|
||||
assert_eq!(
|
||||
settings,
|
||||
&Settings {
|
||||
album_art_pattern: "test_pattern".to_owned(),
|
||||
reindex_every_n_seconds: 31,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
@ -16,5 +16,5 @@ pub fn prepare_test_directory<T: AsRef<str>>(test_name: T) -> PathBuf {
|
|||
std::fs::remove_dir_all(&output_dir).unwrap();
|
||||
}
|
||||
std::fs::create_dir_all(&output_dir).unwrap();
|
||||
return output_dir;
|
||||
output_dir
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue