Test works
All checks were successful
Rust Build / Check (pull_request) Successful in 26s
Rust Build / Test Suite (pull_request) Successful in 28s
Rust Build / Rustfmt (pull_request) Successful in 29s
Rust Build / Clippy (pull_request) Successful in 27s
Rust Build / build (pull_request) Successful in 25s
All checks were successful
Rust Build / Check (pull_request) Successful in 26s
Rust Build / Test Suite (pull_request) Successful in 28s
Rust Build / Rustfmt (pull_request) Successful in 29s
Rust Build / Clippy (pull_request) Successful in 27s
Rust Build / build (pull_request) Successful in 25s
This commit is contained in:
13
src/album.rs
13
src/album.rs
@@ -2,15 +2,28 @@ pub mod collection {
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::default::Default;
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::BufReader;
|
||||
|
||||
fn is_set(num: &i32) -> bool {
|
||||
*num >= 0
|
||||
}
|
||||
|
||||
pub fn parse_album(filepath: &String) -> Result<Album, serde_json::Error> {
|
||||
let file = File::open(filepath).expect("Failed to open file");
|
||||
let reader = BufReader::new(file);
|
||||
|
||||
serde_json::from_reader(reader)
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||
pub struct Album {
|
||||
#[serde(skip_serializing_if = "String::is_empty")]
|
||||
#[serde(alias = "album")]
|
||||
pub title: String,
|
||||
#[serde(skip_serializing_if = "String::is_empty")]
|
||||
#[serde(alias = "album_artist")]
|
||||
pub artist: String,
|
||||
pub genre: String,
|
||||
pub year: i32,
|
||||
pub track_count: i32,
|
||||
|
@@ -155,14 +155,27 @@ mod song_tests {
|
||||
mod album_tests {
|
||||
|
||||
use crate::utils;
|
||||
use icarus_models::album::collection::Album;
|
||||
use icarus_models::album;
|
||||
|
||||
#[test]
|
||||
fn parse_album() {
|
||||
let test_dir = utils::get_tests_directory();
|
||||
if utils::does_directory_exists(&test_dir) {
|
||||
let album = Album::default();
|
||||
let album_file: String = test_dir + &String::from("album.json");
|
||||
println!("Album file: {:?}", album_file);
|
||||
|
||||
// let album = Album::default();
|
||||
match album::collection::parse_album(&album_file) {
|
||||
Ok(album) => {
|
||||
println!("Album title: {}", album.title);
|
||||
assert_eq!(album.title.is_empty(), false);
|
||||
assert_eq!(album.artist.is_empty(), false);
|
||||
assert_eq!(album.tracks.is_empty(), false);
|
||||
}
|
||||
Err(err) => {
|
||||
assert!(false, "Error parsing album json file: {:?}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user