Skip to content

Commit

Permalink
test_reorder_queue, use reorder_queue
Browse files Browse the repository at this point in the history
  • Loading branch information
ddboline committed Aug 18, 2024
1 parent 50066ff commit 88e6125
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
8 changes: 7 additions & 1 deletion movie_collection_lib/src/make_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,15 @@ pub async fn make_queue_worker(
} else if !del_files.is_empty() {
for file in del_files {
match file {
PathOrIndex::Index(idx) => mq.remove_from_queue_by_idx(*idx).await?,
PathOrIndex::Index(idx) => {
mq.remove_from_queue_by_idx(*idx).await?;
}
PathOrIndex::Path(path) => {
mq.remove_from_queue_by_path(&path.to_string_lossy())
.await?;
}
};
mq.reorder_queue().await?;
}
} else if add_files.is_empty() {
let movie_queue = mq.print_movie_queue(patterns, None, None, None).await?;
Expand All @@ -101,6 +104,7 @@ pub async fn make_queue_worker(
if let PathOrIndex::Path(path) = &add_files[0] {
mq.insert_into_queue(max_idx + 1, &path.to_string_lossy())
.await?;
mq.reorder_queue().await?;
} else {
return Err(format_err!("No file specified"));
}
Expand All @@ -123,12 +127,14 @@ pub async fn make_queue_worker(
}
}
}
mq.reorder_queue().await?;
} else {
for file in add_files {
let max_idx = mq.get_max_queue_index().await?;
if let PathOrIndex::Path(path) = file {
mq.insert_into_queue(max_idx + 1, &path.to_string_lossy())
.await?;
mq.reorder_queue().await?;
} else {
return Err(format_err!("{} is not a path", file));
}
Expand Down
17 changes: 16 additions & 1 deletion movie_collection_lib/src/movie_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,10 @@ mod tests {
use anyhow::Error;
use stdout_channel::{MockStdout, StdoutChannel};

use crate::{config::Config, movie_collection::MovieCollection, pgpool::PgPool};
use crate::{
config::Config, movie_collection::MovieCollection, movie_queue::MovieQueueDB,
pgpool::PgPool,
};

#[tokio::test]
#[ignore]
Expand All @@ -1055,4 +1058,16 @@ mod tests {
assert_eq!(files.len(), 2);
Ok(())
}

#[tokio::test]
#[ignore]
async fn test_reorder_queue() -> Result<(), Error> {
let config = Config::with_config()?;
let pool = PgPool::new(&config.pgurl)?;
let mock_stdout = MockStdout::new();
let stdout = StdoutChannel::with_mock_stdout(mock_stdout.clone(), mock_stdout.clone());
let mc = MovieQueueDB::new(&config, &pool, &stdout);
mc.reorder_queue().await?;
Ok(())
}
}

0 comments on commit 88e6125

Please sign in to comment.