Name cleanup
This commit is contained in:
parent
cbb7e7b97c
commit
0b0bfac8fb
4 changed files with 26 additions and 24 deletions
|
@ -11,7 +11,6 @@ use std::path;
|
||||||
use toml;
|
use toml;
|
||||||
|
|
||||||
use crate::db::ConnectionSource;
|
use crate::db::ConnectionSource;
|
||||||
use crate::db::DB;
|
|
||||||
use crate::db::{ddns_config, misc_settings, mount_points, users};
|
use crate::db::{ddns_config, misc_settings, mount_points, users};
|
||||||
use crate::ddns::DDNSConfig;
|
use crate::ddns::DDNSConfig;
|
||||||
use crate::errors::*;
|
use crate::errors::*;
|
||||||
|
@ -294,7 +293,8 @@ fn clean_path_string(path_string: &str) -> path::PathBuf {
|
||||||
path::Path::new(path_string.deref()).iter().collect()
|
path::Path::new(path_string.deref()).iter().collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _get_test_db(name: &str) -> DB {
|
#[cfg(test)]
|
||||||
|
fn get_test_db(name: &str) -> crate::db::DB {
|
||||||
let mut db_path = path::PathBuf::new();
|
let mut db_path = path::PathBuf::new();
|
||||||
db_path.push("test");
|
db_path.push("test");
|
||||||
db_path.push(name);
|
db_path.push(name);
|
||||||
|
@ -302,12 +302,12 @@ fn _get_test_db(name: &str) -> DB {
|
||||||
fs::remove_file(&db_path).unwrap();
|
fs::remove_file(&db_path).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
DB::new(&db_path).unwrap()
|
crate::db::DB::new(&db_path).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_amend() {
|
fn test_amend() {
|
||||||
let db = _get_test_db("amend.sqlite");
|
let db = get_test_db("amend.sqlite");
|
||||||
|
|
||||||
let initial_config = Config {
|
let initial_config = Config {
|
||||||
album_art_pattern: Some("file\\.png".into()),
|
album_art_pattern: Some("file\\.png".into()),
|
||||||
|
@ -361,7 +361,7 @@ fn test_amend() {
|
||||||
fn test_amend_preserve_password_hashes() {
|
fn test_amend_preserve_password_hashes() {
|
||||||
use self::users::dsl::*;
|
use self::users::dsl::*;
|
||||||
|
|
||||||
let db = _get_test_db("amend_preserve_password_hashes.sqlite");
|
let db = get_test_db("amend_preserve_password_hashes.sqlite");
|
||||||
let initial_hash: String;
|
let initial_hash: String;
|
||||||
let new_hash: String;
|
let new_hash: String;
|
||||||
|
|
||||||
|
@ -425,7 +425,7 @@ fn test_amend_preserve_password_hashes() {
|
||||||
fn test_amend_ignore_blank_users() {
|
fn test_amend_ignore_blank_users() {
|
||||||
use self::users::dsl::*;
|
use self::users::dsl::*;
|
||||||
|
|
||||||
let db = _get_test_db("amend_ignore_blank_users.sqlite");
|
let db = get_test_db("amend_ignore_blank_users.sqlite");
|
||||||
|
|
||||||
{
|
{
|
||||||
let config = Config {
|
let config = Config {
|
||||||
|
@ -472,7 +472,7 @@ fn test_amend_ignore_blank_users() {
|
||||||
fn test_toggle_admin() {
|
fn test_toggle_admin() {
|
||||||
use self::users::dsl::*;
|
use self::users::dsl::*;
|
||||||
|
|
||||||
let db = _get_test_db("amend_toggle_admin.sqlite");
|
let db = get_test_db("amend_toggle_admin.sqlite");
|
||||||
|
|
||||||
let initial_config = Config {
|
let initial_config = Config {
|
||||||
album_art_pattern: None,
|
album_art_pattern: None,
|
||||||
|
@ -517,7 +517,7 @@ fn test_toggle_admin() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_preferences_read_write() {
|
fn test_preferences_read_write() {
|
||||||
let db = _get_test_db("preferences_read_write.sqlite");
|
let db = get_test_db("preferences_read_write.sqlite");
|
||||||
|
|
||||||
let initial_config = Config {
|
let initial_config = Config {
|
||||||
album_art_pattern: None,
|
album_art_pattern: None,
|
||||||
|
|
|
@ -86,7 +86,7 @@ impl ConnectionSource for DB {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub fn _get_test_db(name: &str) -> DB {
|
pub fn get_test_db(name: &str) -> DB {
|
||||||
use crate::config;
|
use crate::config;
|
||||||
let config_path = Path::new("test/config.toml");
|
let config_path = Path::new("test/config.toml");
|
||||||
let config = config::parse_toml_file(&config_path).unwrap();
|
let config = config::parse_toml_file(&config_path).unwrap();
|
||||||
|
@ -106,12 +106,12 @@ pub fn _get_test_db(name: &str) -> DB {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_migrations_up() {
|
fn test_migrations_up() {
|
||||||
_get_test_db("migrations_up.sqlite");
|
get_test_db("migrations_up.sqlite");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_migrations_down() {
|
fn test_migrations_down() {
|
||||||
let db = _get_test_db("migrations_down.sqlite");
|
let db = get_test_db("migrations_down.sqlite");
|
||||||
db.migrate_down().unwrap();
|
db.migrate_down().unwrap();
|
||||||
db.migrate_up().unwrap();
|
db.migrate_up().unwrap();
|
||||||
}
|
}
|
||||||
|
|
16
src/index.rs
16
src/index.rs
|
@ -733,7 +733,7 @@ where
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_populate() {
|
fn test_populate() {
|
||||||
let db = db::_get_test_db("populate.sqlite");
|
let db = db::get_test_db("populate.sqlite");
|
||||||
update(&db).unwrap();
|
update(&db).unwrap();
|
||||||
update(&db).unwrap(); // Check that subsequent updates don't run into conflicts
|
update(&db).unwrap(); // Check that subsequent updates don't run into conflicts
|
||||||
|
|
||||||
|
@ -758,7 +758,7 @@ fn test_metadata() {
|
||||||
let mut artwork_path = target.clone();
|
let mut artwork_path = target.clone();
|
||||||
artwork_path.push("Folder.png");
|
artwork_path.push("Folder.png");
|
||||||
|
|
||||||
let db = db::_get_test_db("metadata.sqlite");
|
let db = db::get_test_db("metadata.sqlite");
|
||||||
update(&db).unwrap();
|
update(&db).unwrap();
|
||||||
|
|
||||||
let connection = db.get_connection();
|
let connection = db.get_connection();
|
||||||
|
@ -788,7 +788,7 @@ fn test_browse_top_level() {
|
||||||
let mut root_path = PathBuf::new();
|
let mut root_path = PathBuf::new();
|
||||||
root_path.push("root");
|
root_path.push("root");
|
||||||
|
|
||||||
let db = db::_get_test_db("browse_top_level.sqlite");
|
let db = db::get_test_db("browse_top_level.sqlite");
|
||||||
update(&db).unwrap();
|
update(&db).unwrap();
|
||||||
let results = browse(&db, Path::new("")).unwrap();
|
let results = browse(&db, Path::new("")).unwrap();
|
||||||
|
|
||||||
|
@ -809,7 +809,7 @@ fn test_browse() {
|
||||||
tobokegao_path.push("root");
|
tobokegao_path.push("root");
|
||||||
tobokegao_path.push("Tobokegao");
|
tobokegao_path.push("Tobokegao");
|
||||||
|
|
||||||
let db = db::_get_test_db("browse.sqlite");
|
let db = db::get_test_db("browse.sqlite");
|
||||||
update(&db).unwrap();
|
update(&db).unwrap();
|
||||||
let results = browse(&db, Path::new("root")).unwrap();
|
let results = browse(&db, Path::new("root")).unwrap();
|
||||||
|
|
||||||
|
@ -826,7 +826,7 @@ fn test_browse() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_flatten() {
|
fn test_flatten() {
|
||||||
let db = db::_get_test_db("flatten.sqlite");
|
let db = db::get_test_db("flatten.sqlite");
|
||||||
update(&db).unwrap();
|
update(&db).unwrap();
|
||||||
let results = flatten(&db, Path::new("root")).unwrap();
|
let results = flatten(&db, Path::new("root")).unwrap();
|
||||||
assert_eq!(results.len(), 12);
|
assert_eq!(results.len(), 12);
|
||||||
|
@ -835,7 +835,7 @@ fn test_flatten() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_random() {
|
fn test_random() {
|
||||||
let db = db::_get_test_db("random.sqlite");
|
let db = db::get_test_db("random.sqlite");
|
||||||
update(&db).unwrap();
|
update(&db).unwrap();
|
||||||
let results = get_random_albums(&db, 1).unwrap();
|
let results = get_random_albums(&db, 1).unwrap();
|
||||||
assert_eq!(results.len(), 1);
|
assert_eq!(results.len(), 1);
|
||||||
|
@ -843,7 +843,7 @@ fn test_random() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_recent() {
|
fn test_recent() {
|
||||||
let db = db::_get_test_db("recent.sqlite");
|
let db = db::get_test_db("recent.sqlite");
|
||||||
update(&db).unwrap();
|
update(&db).unwrap();
|
||||||
let results = get_recent_albums(&db, 2).unwrap();
|
let results = get_recent_albums(&db, 2).unwrap();
|
||||||
assert_eq!(results.len(), 2);
|
assert_eq!(results.len(), 2);
|
||||||
|
@ -852,7 +852,7 @@ fn test_recent() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_song() {
|
fn test_get_song() {
|
||||||
let db = db::_get_test_db("get_song.sqlite");
|
let db = db::get_test_db("get_song.sqlite");
|
||||||
update(&db).unwrap();
|
update(&db).unwrap();
|
||||||
|
|
||||||
let mut song_path = PathBuf::new();
|
let mut song_path = PathBuf::new();
|
||||||
|
|
|
@ -181,13 +181,15 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
// Select songs. Not using Diesel because we need to LEFT JOIN using a custom column
|
// Select songs. Not using Diesel because we need to LEFT JOIN using a custom column
|
||||||
let query = diesel::sql_query(r#"
|
let query = diesel::sql_query(
|
||||||
|
r#"
|
||||||
SELECT s.id, s.path, s.parent, s.track_number, s.disc_number, s.title, s.artist, s.album_artist, s.year, s.album, s.artwork, s.duration
|
SELECT s.id, s.path, s.parent, s.track_number, s.disc_number, s.title, s.artist, s.album_artist, s.year, s.album, s.artwork, s.duration
|
||||||
FROM playlist_songs ps
|
FROM playlist_songs ps
|
||||||
LEFT JOIN songs s ON ps.path = s.path
|
LEFT JOIN songs s ON ps.path = s.path
|
||||||
WHERE ps.playlist = ?
|
WHERE ps.playlist = ?
|
||||||
ORDER BY ps.ordering
|
ORDER BY ps.ordering
|
||||||
"#);
|
"#,
|
||||||
|
);
|
||||||
let query = query.clone().bind::<sql_types::Integer, _>(playlist.id);
|
let query = query.clone().bind::<sql_types::Integer, _>(playlist.id);
|
||||||
songs = query.get_results(connection.deref())?;
|
songs = query.get_results(connection.deref())?;
|
||||||
}
|
}
|
||||||
|
@ -227,7 +229,7 @@ where
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_create_playlist() {
|
fn test_create_playlist() {
|
||||||
let db = db::_get_test_db("create_playlist.sqlite");
|
let db = db::get_test_db("create_playlist.sqlite");
|
||||||
|
|
||||||
let found_playlists = list_playlists("test_user", &db).unwrap();
|
let found_playlists = list_playlists("test_user", &db).unwrap();
|
||||||
assert!(found_playlists.is_empty());
|
assert!(found_playlists.is_empty());
|
||||||
|
@ -243,7 +245,7 @@ fn test_create_playlist() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_delete_playlist() {
|
fn test_delete_playlist() {
|
||||||
let db = db::_get_test_db("delete_playlist.sqlite");
|
let db = db::get_test_db("delete_playlist.sqlite");
|
||||||
let playlist_content = Vec::new();
|
let playlist_content = Vec::new();
|
||||||
|
|
||||||
save_playlist("chill_and_grill", "test_user", &playlist_content, &db).unwrap();
|
save_playlist("chill_and_grill", "test_user", &playlist_content, &db).unwrap();
|
||||||
|
@ -264,7 +266,7 @@ fn test_delete_playlist() {
|
||||||
fn test_fill_playlist() {
|
fn test_fill_playlist() {
|
||||||
use crate::index;
|
use crate::index;
|
||||||
|
|
||||||
let db = db::_get_test_db("fill_playlist.sqlite");
|
let db = db::get_test_db("fill_playlist.sqlite");
|
||||||
index::update(&db).unwrap();
|
index::update(&db).unwrap();
|
||||||
|
|
||||||
let mut playlist_content: Vec<String> = index::flatten(&db, Path::new("root"))
|
let mut playlist_content: Vec<String> = index::flatten(&db, Path::new("root"))
|
||||||
|
|
Loading…
Add table
Reference in a new issue