diff --git a/.env.example b/.env.example deleted file mode 100644 index 7ab1bf9..0000000 --- a/.env.example +++ /dev/null @@ -1,2 +0,0 @@ -MUSIXMATCH_EMAIL=mail@example.com -MUSIXMATCH_PASSWORD=super-secret diff --git a/Cargo.toml b/Cargo.toml index 525922b..17b0119 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,7 +49,6 @@ env_logger = "0.10.0" dotenvy = "0.15.5" tokio = { version = "1.20.0", features = ["macros"] } futures = "0.3.21" -path_macro = "1.0.0" [profile.release] strip = true diff --git a/README.md b/README.md index 9e83d62..95a10f6 100644 --- a/README.md +++ b/README.md @@ -24,12 +24,3 @@ lyrics site/app. If you want to use Musixmatch data for this purpose, you will have to give them money (see their [commercial plans](https://developer.musixmatch.com/plans)) and use their [official API](https://developer.musixmatch.com/documentation). - -## Development info - -Running the tests requires Musixmatch credentials. The credentials are read -from the `MUSIXMATCH_EMAIL` and `MUSIXMATCH_PASSWORD` environment variables. - -To make local development easier, I have included `dotenvy` to read the -credentials from an `.env` file. Copy the `.env.example` file -in the root directory, rename it to `.env` and fill in your credentials. diff --git a/src/lib.rs b/src/lib.rs index e8b014c..ae4f684 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -112,7 +112,7 @@ impl Musixmatch { .gzip(true) .cookie_store(true) .build() - .expect("http client could not be constructed"); + .unwrap(); Self { inner: Arc::new(MusixmatchRef { diff --git a/tests/tests.rs b/tests/tests.rs index 2159cfb..00a3663 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1,6 +1,3 @@ -use std::path::{Path, PathBuf}; - -use path_macro::path; use rstest::rstest; use time::macros::{date, datetime}; @@ -22,7 +19,7 @@ fn init() { .unwrap(); } -fn new_mxm() -> Musixmatch { +pub fn new_mxm() -> Musixmatch { Musixmatch::new( &std::env::var("MUSIXMATCH_EMAIL").unwrap(), &std::env::var("MUSIXMATCH_PASSWORD").unwrap(), @@ -30,10 +27,6 @@ fn new_mxm() -> Musixmatch { ) } -fn testfile>(name: P) -> PathBuf { - path!(env!("CARGO_MANIFEST_DIR") / "testfiles" / name) -} - mod album { use super::*; use musixmatch_inofficial::models::AlbumType; @@ -686,7 +679,7 @@ mod track { mod lyrics { use futures::stream::{self, StreamExt}; - use std::{fs::File, io::BufWriter}; + use std::{fs::File, io::BufWriter, path::Path}; use super::*; @@ -763,7 +756,7 @@ mod lyrics { #[tokio::test] async fn download_testdata() { - let json_path = testfile("lyrics.json"); + let json_path = Path::new("testfiles/lyrics.json"); if json_path.exists() { return; } @@ -779,7 +772,7 @@ mod lyrics { #[tokio::test] async fn download_testdata_translation() { - let json_path = testfile("translation.json"); + let json_path = Path::new("testfiles/translation.json"); if json_path.exists() { return; } @@ -825,7 +818,7 @@ mod lyrics { } mod subtitles { - use std::{fs::File, io::BufWriter}; + use std::{fs::File, io::BufWriter, path::Path}; use super::*; use musixmatch_inofficial::models::SubtitleFormat; @@ -932,7 +925,7 @@ mod subtitles { #[tokio::test] async fn download_testdata() { - let json_path = testfile("subtitles.json"); + let json_path = Path::new("testfiles/subtitles.json"); if json_path.exists() { return; } @@ -953,17 +946,15 @@ mod subtitles { } mod translation { - use std::{fs::File, io::BufReader}; + use std::{fs::File, io::BufReader, path::Path}; use musixmatch_inofficial::models::{Lyrics, Subtitle, TranslationList, TranslationMap}; - use crate::testfile; - #[test] fn translation_test() { - let lyrics_path = testfile("lyrics.json"); - let subtitles_path = testfile("subtitles.json"); - let translation_path = testfile("translation.json"); + let lyrics_path = Path::new("testfiles/lyrics.json"); + let subtitles_path = Path::new("testfiles/subtitles.json"); + let translation_path = Path::new("testfiles/translation.json"); let lyrics: Lyrics = serde_json::from_reader(BufReader::new(File::open(lyrics_path).unwrap())).unwrap(); @@ -975,13 +966,13 @@ mod translation { let t_map = TranslationMap::from(translations); let lyrics_trans = t_map.translate_lyrics(&lyrics.lyrics_body); - let expected_lyrics = std::fs::read_to_string(testfile("translated_lyrics.txt")).unwrap(); + let expected_lyrics = std::fs::read_to_string("testfiles/translated_lyrics.txt").unwrap(); assert_eq!(lyrics_trans.trim(), expected_lyrics.trim()); let subtitles_trans = t_map.translate_subtitles(&subtitle.to_lines().unwrap()); - let expected_lrc = std::fs::read_to_string(testfile("translated_subtitles.lrc")).unwrap(); - let expected_ttml = std::fs::read_to_string(testfile("translated_subtitles.xml")).unwrap(); + let expected_lrc = std::fs::read_to_string("testfiles/translated_subtitles.lrc").unwrap(); + let expected_ttml = std::fs::read_to_string("testfiles/translated_subtitles.xml").unwrap(); assert_eq!(subtitles_trans.to_lrc().trim(), expected_lrc.trim()); assert_eq!(subtitles_trans.to_ttml().trim(), expected_ttml.trim());