diff options
Diffstat (limited to 'src/updater.rs')
| -rw-r--r-- | src/updater.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/updater.rs b/src/updater.rs index a21f378..7b63bf7 100644 --- a/src/updater.rs +++ b/src/updater.rs @@ -103,11 +103,25 @@ pub fn update_images(now: &DateTime<Utc>, db: &dyn Db, reg: &dyn Registries, fil db.delete_tag(image_id, gone); } db.update_last_checked(image_id, now); + // @CLEANUP: Propagate the update to other instances. We should really avoid + // this situation in the first place + for j in (i + 1)..image_ids.len() { + if image_ids[j] == image_id { + last_checkeds[j] = *now; + } + } Ok((fetched_tags, None)) } None => { db.update_last_checked(image_id, now); + // @CLEANUP: Propagate the update to other instances. We should really avoid + // this situation in the first place + for j in (i + 1)..image_ids.len() { + if image_ids[j] == image_id { + last_checkeds[j] = *now; + } + } Err(format!("image not found: {}", image_name)) } } @@ -619,4 +633,26 @@ mod tests { assert!(db.get_image("registry.hub.docker.com", "redis").is_some()); assert!(db.get_tags_sorted(2).is_empty()); } + + #[test] + fn same_image_multiple_files_fetches_twice() { + crate::metrics::init(); + let now = Utc.with_ymd_and_hms(2000, 1, 1, 0, 0, 0).unwrap(); + let db = StubDb::default(); + let reg = StubRegistry::default(); + + reg.add_tag("registry.hub.docker.com", "nginx", "1.21", "sha256:0000000000000000000000000000000000000000000000000000000000000001"); + reg.add_tag("registry.hub.docker.com", "nginx", "1.22", "sha256:0000000000000000000000000000000000000000000000000000000000000002"); + + let files = vec![ + FileInput { path: "/a".into(), content: "image: nginx:1.21".into(), images: vec![7..17] }, + FileInput { path: "/b".into(), content: "image: nginx:1.21".into(), images: vec![7..17] }, + ]; + let mut outcomes = vec![]; + update_images(&now, &db, ®, &files, &mut outcomes); + + assert_eq!(outcomes[0].as_ref().unwrap()[0].content, "1.22"); + assert_eq!(outcomes[1].as_ref().unwrap()[0].content, "1.22"); + assert_eq!(reg.tags_calls.borrow()[&("registry.hub.docker.com".to_string(), "nginx".to_string())], 1); + } } |
