Separate test inputs from outputs

This commit is contained in:
Antoine Gersant 2020-09-19 16:58:19 -07:00
parent 00a1ca18cf
commit cd63564c03
29 changed files with 40 additions and 20 deletions

5
.gitignore vendored
View file

@ -1,10 +1,7 @@
target
release
*.res
test/*.sqlite
*.sqlite-journal
*.sqlite-wal
*.sqlite-shm
test-output
tmp
TestConfig*
index-flame-graph.html

View file

@ -16,7 +16,7 @@ Polaris supports a few command line arguments which are useful during developmen
- `-c some/config.toml` lets you use a configuration file to add content to the database. This can be useful if you frequently delete the database and would like to automate the first time flow. The configuration format is not documented but can be inferred by looking at the `Config` struct in `config.rs`.
- `-f` (on Linux) makes Polaris not fork into a separate process.
Putting it all together, a typical command to compile and run the program would be: `cargo run -- -w web -s docs/swagger -d test/my.db`
Putting it all together, a typical command to compile and run the program would be: `cargo run -- -w web -s docs/swagger -d test-output/my.db`
While Polaris is running, access the web UI at [http://localhost:5050](http://localhost:5050).

View file

@ -284,7 +284,9 @@ fn clean_path_string(path_string: &str) -> path::PathBuf {
#[cfg(test)]
fn get_test_db(name: &str) -> crate::db::DB {
let mut db_path = path::PathBuf::new();
db_path.push("test");
db_path.push("test-output");
fs::create_dir_all(&db_path).unwrap();
db_path.push(name);
if db_path.exists() {
fs::remove_file(&db_path).unwrap();

View file

@ -84,17 +84,20 @@ impl DB {
#[cfg(test)]
pub fn get_test_db(name: &str) -> DB {
use crate::config;
let config_path = Path::new("test/config.toml");
let config_path = Path::new("test-data/config.toml");
let config = config::parse_toml_file(&config_path).unwrap();
let mut db_path = std::path::PathBuf::new();
db_path.push("test");
db_path.push("test-output");
std::fs::create_dir_all(&db_path).unwrap();
db_path.push(name);
if db_path.exists() {
std::fs::remove_file(&db_path).unwrap();
}
let db = DB::new(&db_path).unwrap();
config::reset(&db).unwrap();
config::amend(&db, &config).unwrap();
db

View file

@ -6,10 +6,10 @@ use log::error;
use metaflac;
use mp3_duration;
use mp4ameta;
use opus_headers;
use regex::Regex;
use std::fs;
use std::path::Path;
use opus_headers;
use crate::utils;
use crate::utils::AudioFormat;
@ -291,9 +291,24 @@ fn test_read_metadata() {
duration: Some(0),
..sample_tags.clone()
};
assert_eq!(read(Path::new("test/sample.mp3")).unwrap(), mp3_sample_tag);
assert_eq!(read(Path::new("test/sample.ogg")).unwrap(), sample_tags);
assert_eq!(read(Path::new("test/sample.flac")).unwrap(), flac_sample_tag);
assert_eq!(read(Path::new("test/sample.m4a")).unwrap(), m4a_sample_tag);
assert_eq!(read(Path::new("test/sample.opus")).unwrap(), sample_tags);
assert_eq!(
read(Path::new("test-data/formats/sample.mp3")).unwrap(),
mp3_sample_tag
);
assert_eq!(
read(Path::new("test-data/formats/sample.ogg")).unwrap(),
sample_tags
);
assert_eq!(
read(Path::new("test-data/formats/sample.flac")).unwrap(),
flac_sample_tag
);
assert_eq!(
read(Path::new("test-data/formats/sample.m4a")).unwrap(),
m4a_sample_tag
);
assert_eq!(
read(Path::new("test-data/formats/sample.opus")).unwrap(),
sample_tags
);
}

View file

@ -20,8 +20,8 @@ fn test_populate() {
#[test]
fn test_metadata() {
let mut target = PathBuf::new();
target.push("test");
target.push("collection");
target.push("test-data");
target.push("small-collection");
target.push("Tobokegao");
target.push("Picnic");

View file

@ -55,11 +55,14 @@ pub type ServiceType = RocketTestService;
impl TestService for RocketTestService {
fn new(db_name: &str) -> Self {
let mut db_path = PathBuf::new();
db_path.push("test");
db_path.push("test-output");
fs::create_dir_all(&db_path).unwrap();
db_path.push(format!("{}.sqlite", db_name));
if db_path.exists() {
fs::remove_file(&db_path).unwrap();
}
let db = DB::new(&db_path).unwrap();
let web_dir_path = PathBuf::from("web");

View file

@ -18,7 +18,7 @@ const TEST_DB_PREFIX: &str = "service-test-";
const TEST_USERNAME: &str = "test_user";
const TEST_PASSWORD: &str = "test_password";
const TEST_MOUNT_NAME: &str = "collection";
const TEST_MOUNT_SOURCE: &str = "test/collection";
const TEST_MOUNT_SOURCE: &str = "test-data/small-collection";
pub trait TestService {
fn new(db_name: &str) -> Self;
@ -180,7 +180,7 @@ fn test_service_settings() {
},
vfs::MountPoint {
name: "more_music".into(),
source: "test/collection".into(),
source: "test-data/small-collection".into(),
},
]),
prefix_url: Some("my_prefix".to_owned()),

View file

@ -2,7 +2,7 @@ album_art_pattern = '^Folder\.(png|jpg|jpeg)$'
[[mount_dirs]]
name = 'root'
source = 'test/collection'
source = 'test-data/small-collection'
[[users]]
name = 'test_user'

View file

Before

(image error) Size: 30 KiB

After

(image error) Size: 30 KiB

View file

Before

(image error) Size: 37 KiB

After

(image error) Size: 37 KiB