Skip to content

Commit

Permalink
Fix dry run III
Browse files Browse the repository at this point in the history
  • Loading branch information
quambene committed Mar 20, 2024
1 parent c75c421 commit f973043
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
24 changes: 8 additions & 16 deletions src/bookmarks/bookmark_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ where
| RunMode::FetchAll
| RunMode::FetchUrls(_)
| RunMode::FetchDiff(_)
| RunMode::Update => {
| RunMode::Update
| RunMode::DryRun => {
self.execute_actions(bookmark_manager).await?;
self.add_underlyings(bookmark_manager);

Expand Down Expand Up @@ -176,7 +177,7 @@ where
RunMode::DryRun => {
bookmark_manager
.target_bookmarks_mut()
.set_action(&Action::None);
.set_action(&Action::DryRun);
}
RunMode::None => {
bookmark_manager
Expand All @@ -191,12 +192,6 @@ where
Status::Removed => target_bookmark.set_action(Action::Remove),
Status::Added | Status::None => (),
}
} else {
match target_bookmark.status() {
Status::Removed => target_bookmark.set_action(Action::DryRun),
Status::Added => target_bookmark.set_action(Action::DryRun),
Status::None => (),
}
}
}

Expand All @@ -211,8 +206,6 @@ where

if self.config.run_mode != RunMode::DryRun {
bookmark.set_action(Action::Remove);
} else {
bookmark.set_action(Action::DryRun);
}
}
}
Expand All @@ -232,7 +225,7 @@ where
.filter(|bookmark| bookmark.action() != &Action::None)
.collect::<Vec<_>>();

if bookmarks.len() == 0 {
if bookmarks.is_empty() {
return Ok(());
}

Expand Down Expand Up @@ -587,11 +580,10 @@ mod tests {

let res = service.set_actions(&mut bookmark_manager, now);
assert!(res.is_ok());

let bookmarks = bookmark_manager.target_bookmarks();
assert_eq!(bookmarks.get(&url1).unwrap().action, Action::DryRun);
assert_eq!(bookmarks.get(&url2).unwrap().action, Action::DryRun);
assert_eq!(bookmarks.get(&url3).unwrap().action, Action::None);
assert!(bookmark_manager
.target_bookmarks()
.values()
.any(|bookmark| bookmark.action == Action::DryRun));
}

#[tokio::test]
Expand Down
8 changes: 7 additions & 1 deletion src/bookmarks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,13 @@ impl From<&TargetBookmarks> for JsonBookmarks {
fn from(target_bookmarks: &TargetBookmarks) -> Self {
let mut bookmarks = target_bookmarks
.values()
.filter(|bookmark| bookmark.action() != &Action::DryRun)
.filter(|bookmark| {
if bookmark.action() == &Action::DryRun {
bookmark.status() == &Status::None

Check warning on line 320 in src/bookmarks/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/bookmarks/mod.rs#L320

Added line #L320 was not covered by tests
} else {
true
}
})
.map(JsonBookmark::from)
.collect::<Vec<_>>();
bookmarks.sort_by(Self::compare);
Expand Down

0 comments on commit f973043

Please sign in to comment.