arnaucube
arnaucube/octo-tuiPublic Self-hosted repository
octo-tui/src/test_support.rs
src/test_support.rsRaw
 1//! Fixtures and audio-transport doubles compiled only by the test harness.
 2use crate::{
 3    model::Song,
 4    player::{Playback, PlayerEvent},
 5};
 6
 7pub fn songs() -> Vec<Song> {
 8    (0..8)
 9        .map(|index| Song {
10            id: format!("track-{index}"),
11            title: format!("Track {index}"),
12            artist: "Test artist".into(),
13            album: "Test album".into(),
14            duration: 240,
15            is_external: index >= 4,
16            octo_suggested_by: (index >= 4).then(|| "Last.fm".into()),
17            ..Default::default()
18        })
19        .collect()
20}
21
22#[derive(Default)]
23pub struct TestPlayback {
24    pub events: std::sync::Arc<std::sync::Mutex<Vec<PlayerEvent>>>,
25    pub commands: std::sync::Arc<std::sync::Mutex<Vec<serde_json::Value>>>,
26}
27impl Playback for TestPlayback {
28    fn command(&mut self, command: serde_json::Value) -> anyhow::Result<()> {
29        self.commands.lock().unwrap().push(command);
30        Ok(())
31    }
32    fn drain_events(&self) -> Vec<PlayerEvent> {
33        self.events.lock().unwrap().drain(..).collect()
34    }
35}