Exclude some from coverage

This commit is contained in:
Wojciech Kozlowski 2024-08-28 16:46:09 +02:00
parent 041a91de4c
commit 713cbdc26c

View File

@ -14,6 +14,7 @@ use musichoard::{
use crate::tui::lib::interface::musicbrainz::{Error, IMusicBrainz, Match};
// GRCOV_EXCL_START
pub struct MusicBrainz<Http> {
client: MusicBrainzClient<Http>,
}
@ -62,206 +63,4 @@ fn from_search_release_group_response_release_group(
album.set_musicbrainz_ref(entity.id.into());
Match::new(entity.score, album)
}
// #[cfg(test)]
// mod tests {
// use mockall::{predicate, Sequence};
// use crate::collection::album::AlbumId;
// use super::*;
// #[test]
// fn match_type() {
// let album = Album::new(AlbumId::new("an album"), AlbumDate::default(), None, vec![]);
// let hit = Match::new(56, album);
// assert!(!format!("{hit:?}").is_empty());
// }
// #[test]
// fn lookup_artist_release_group() {
// let mut client = MockIMusicBrainzApiClient::new();
// let url = format!(
// "https://musicbrainz.org/ws/2/artist/{mbid}?inc=release-groups",
// mbid = "00000000-0000-0000-0000-000000000000",
// );
// let release_group = LookupReleaseGroup {
// id: String::from("11111111-1111-1111-1111-111111111111"),
// title: String::from("an album"),
// first_release_date: String::from("1986-04"),
// primary_type: SerdeAlbumPrimaryType(AlbumPrimaryType::Album),
// secondary_types: vec![SerdeAlbumSecondaryType(AlbumSecondaryType::Compilation)],
// };
// let response = ResponseLookupArtist {
// release_groups: vec![release_group],
// };
// // For code coverage of derive(Debug).
// assert!(!format!("{response:?}").is_empty());
// client
// .expect_get()
// .times(1)
// .with(predicate::eq(url))
// .return_once(|_| Ok(response));
// let mut api = MusicBrainzApi::new(client);
// let mbid: Mbid = "00000000-0000-0000-0000-000000000000".try_into().unwrap();
// let results = api.lookup_artist_release_groups(&mbid).unwrap();
// let mut album = Album::new(
// AlbumId::new("an album"),
// (1986, 4),
// Some(AlbumPrimaryType::Album),
// vec![AlbumSecondaryType::Compilation],
// );
// album.set_musicbrainz_ref(
// MbAlbumRef::from_uuid_str("11111111-1111-1111-1111-111111111111").unwrap(),
// );
// let expected = vec![album];
// assert_eq!(results, expected);
// }
// #[test]
// fn search_release_group() {
// let mut client = MockIMusicBrainzApiClient::new();
// let url_title = format!(
// "https://musicbrainz.org/ws/2\
// /release-group\
// ?query=arid%3A{arid}+AND+releasegroup%3A%22{title}%22+AND+firstreleasedate%3A{year}",
// arid = "00000000-0000-0000-0000-000000000000",
// title = "an+album",
// year = "1986"
// );
// let url_rgid = format!(
// "https://musicbrainz.org/ws/2\
// /release-group\
// ?query=arid%3A{arid}+AND+rgid%3A{rgid}",
// arid = "00000000-0000-0000-0000-000000000000",
// rgid = "11111111-1111-1111-1111-111111111111",
// );
// let release_group = SearchReleaseGroup {
// score: 67,
// id: String::from("11111111-1111-1111-1111-111111111111"),
// title: String::from("an album"),
// first_release_date: String::from("1986-04"),
// primary_type: SerdeAlbumPrimaryType(AlbumPrimaryType::Album),
// secondary_types: Some(vec![SerdeAlbumSecondaryType(AlbumSecondaryType::Live)]),
// };
// let response = ResponseSearchReleaseGroup {
// release_groups: vec![release_group],
// };
// // For code coverage of derive(Debug).
// assert!(!format!("{response:?}").is_empty());
// let mut seq = Sequence::new();
// let title_response = response.clone();
// client
// .expect_get()
// .times(1)
// .with(predicate::eq(url_title))
// .return_once(|_| Ok(title_response))
// .in_sequence(&mut seq);
// let rgid_response = response;
// client
// .expect_get()
// .times(1)
// .with(predicate::eq(url_rgid))
// .return_once(|_| Ok(rgid_response))
// .in_sequence(&mut seq);
// let mut album = Album::new(
// AlbumId::new("an album"),
// (1986, 4),
// Some(AlbumPrimaryType::Album),
// vec![AlbumSecondaryType::Live],
// );
// album.set_musicbrainz_ref(
// MbAlbumRef::from_uuid_str("11111111-1111-1111-1111-111111111111").unwrap(),
// );
// let expected = vec![Match::new(67, album)];
// let mut api = MusicBrainzApi::new(client);
// let arid: Mbid = "00000000-0000-0000-0000-000000000000".try_into().unwrap();
// let mut album = Album::new(AlbumId::new("an album"), (1986, 4), None, vec![]);
// let matches = api.search_release_group(&arid, &album).unwrap();
// assert_eq!(matches, expected);
// let rgid = MbAlbumRef::from_uuid_str("11111111-1111-1111-1111-111111111111").unwrap();
// album.set_musicbrainz_ref(rgid);
// let matches = api.search_release_group(&arid, &album).unwrap();
// assert_eq!(matches, expected);
// }
// #[test]
// fn client_errors() {
// let mut client = MockIMusicBrainzApiClient::new();
// let error = ClientError::Client(String::from("get rekt"));
// assert!(!format!("{error:?}").is_empty());
// client
// .expect_get::<ResponseLookupArtist>()
// .times(1)
// .return_once(|_| Err(ClientError::Client(String::from("get rekt scrub"))));
// client
// .expect_get::<ResponseLookupArtist>()
// .times(1)
// .return_once(|_| Err(ClientError::Status(503)));
// client
// .expect_get::<ResponseLookupArtist>()
// .times(1)
// .return_once(|_| Err(ClientError::Status(504)));
// let mut api = MusicBrainzApi::new(client);
// let mbid: Mbid = "00000000-0000-0000-0000-000000000000".try_into().unwrap();
// let error = api.lookup_artist_release_groups(&mbid).unwrap_err();
// assert_eq!(error, Error::Client(String::from("get rekt scrub")));
// let error = api.lookup_artist_release_groups(&mbid).unwrap_err();
// assert_eq!(error, Error::RateLimit);
// let error = api.lookup_artist_release_groups(&mbid).unwrap_err();
// assert_eq!(error, Error::Unknown(504));
// }
// #[test]
// fn from_mb_date() {
// assert_eq!(AlbumDate::from_mb_date("").unwrap(), AlbumDate::default());
// assert_eq!(AlbumDate::from_mb_date("1984").unwrap(), 1984.into());
// assert_eq!(
// AlbumDate::from_mb_date("1984-05").unwrap(),
// (1984, 5).into()
// );
// assert_eq!(
// AlbumDate::from_mb_date("1984-05-18").unwrap(),
// (1984, 5, 18).into()
// );
// assert!(AlbumDate::from_mb_date("1984-get-rekt").is_err());
// }
// #[test]
// fn serde() {
// let primary_type = "\"EP\"";
// let primary_type: SerdeAlbumPrimaryType = serde_json::from_str(primary_type).unwrap();
// let primary_type: AlbumPrimaryType = primary_type.into();
// assert_eq!(primary_type, AlbumPrimaryType::Ep);
// let secondary_type = "\"Field recording\"";
// let secondary_type: SerdeAlbumSecondaryType = serde_json::from_str(secondary_type).unwrap();
// let secondary_type: AlbumSecondaryType = secondary_type.into();
// assert_eq!(secondary_type, AlbumSecondaryType::FieldRecording);
// }
// }
// GRCOV_EXCL_STOP