summaryrefslogtreecommitdiff
path: root/src/registry.rs
diff options
context:
space:
mode:
authorJesper Jensen <jesper@jnsn.dev>2026-02-08 18:34:10 +0100
committerJesper Jensen <jesper@jnsn.dev>2026-02-08 18:34:10 +0100
commitb12254e3bc034faed6c917d12cd33399022ed10c (patch)
tree8be31ee5c6bc26921ddaa5461ab42649dfb062d4 /src/registry.rs
parentda8194ed935e3c7ebeaa93c645db9dc1db4713a6 (diff)
Take the registry tags at construction time
Diffstat (limited to 'src/registry.rs')
-rw-r--r--src/registry.rs98
1 files changed, 34 insertions, 64 deletions
diff --git a/src/registry.rs b/src/registry.rs
index 173f8a7..c1ab4b7 100644
--- a/src/registry.rs
+++ b/src/registry.rs
@@ -324,11 +324,11 @@ impl Registries for HttpRegistry {
}
#[cfg(test)]
-struct StubTag {
- registry: String,
- image: String,
- tag: String,
- digest: String,
+pub struct StubTag {
+ pub registry: String,
+ pub image: String,
+ pub tag: String,
+ pub digest: String,
}
#[cfg(test)]
@@ -338,25 +338,13 @@ pub struct StubRegistry {
}
#[cfg(test)]
-impl Default for StubRegistry {
- fn default() -> Self {
+impl StubRegistry {
+ pub fn new(tags: Vec<StubTag>) -> Self {
return StubRegistry {
- entries: RefCell::new(vec![]),
+ entries: RefCell::new(tags),
tags_calls: RefCell::new(HashMap::new()),
};
}
-}
-
-#[cfg(test)]
-impl StubRegistry {
- pub fn add_tag(&self, registry: &str, image: &str, tag: &str, digest: &str) {
- self.entries.borrow_mut().push(StubTag {
- registry: registry.to_string(),
- image: image.to_string(),
- tag: tag.to_string(),
- digest: digest.to_string(),
- });
- }
pub fn set_digest(&self, registry: &str, image: &str, tag: &str, digest: &str) {
for entry in self.entries.borrow_mut().iter_mut() {
@@ -410,65 +398,47 @@ impl Registries for StubRegistry {
mod tests {
use super::*;
- fn test_get_tags_returns_none_for_unknown(reg: &dyn Registries) {
- assert_eq!(reg.get_tags("docker.io", "unknown"), None);
+ #[test]
+ fn get_tags_returns_none_for_unknown() {
+ let stub = StubRegistry::new(vec![]);
+ assert_eq!(stub.get_tags("docker.io", "unknown"), None);
}
- fn test_get_tags_returns_all(reg: &dyn Registries, stub: &StubRegistry) {
- stub.add_tag("docker.io", "nginx", "1.21", "sha256:abc");
- stub.add_tag("docker.io", "nginx", "1.20", "sha256:def");
- stub.add_tag("docker.io", "nginx", "latest", "sha256:ghi");
- let mut tags = reg.get_tags("docker.io", "nginx").unwrap();
+ #[test]
+ fn get_tags_returns_all() {
+ let stub = StubRegistry::new(vec![
+ StubTag { registry: "docker.io".into(), image: "nginx".into(), tag: "1.21".into(), digest: "sha256:abc".into() },
+ StubTag { registry: "docker.io".into(), image: "nginx".into(), tag: "1.20".into(), digest: "sha256:def".into() },
+ StubTag { registry: "docker.io".into(), image: "nginx".into(), tag: "latest".into(), digest: "sha256:ghi".into() },
+ ]);
+ let mut tags = stub.get_tags("docker.io", "nginx").unwrap();
tags.sort();
assert_eq!(tags, vec!["1.20", "1.21", "latest"]);
}
- fn test_get_digest_returns_none_for_unknown(reg: &dyn Registries) {
- assert_eq!(reg.get_digest("docker.io", "nginx", "1.21"), None);
- }
-
- fn test_get_digest_returns_digest(reg: &dyn Registries, stub: &StubRegistry) {
- stub.add_tag("docker.io", "nginx", "1.21", "sha256:abc123");
-
- assert_eq!(reg.get_digest("docker.io", "nginx", "1.21"), Some("sha256:abc123".to_string()));
- }
-
- fn test_set_digest_updates_existing(reg: &dyn Registries, stub: &StubRegistry) {
- stub.add_tag("docker.io", "nginx", "1.21", "sha256:old");
- stub.set_digest("docker.io", "nginx", "1.21", "sha256:new");
-
- assert_eq!(reg.get_digest("docker.io", "nginx", "1.21"), Some("sha256:new".to_string()));
- }
-
#[test]
- fn conformance_stub_get_tags_unknown() {
- let stub = StubRegistry::default();
- test_get_tags_returns_none_for_unknown(&stub);
+ fn get_digest_returns_none_for_unknown() {
+ let stub = StubRegistry::new(vec![]);
+ assert_eq!(stub.get_digest("docker.io", "nginx", "1.21"), None);
}
#[test]
- fn conformance_stub_get_tags_all() {
- let stub = StubRegistry::default();
- test_get_tags_returns_all(&stub, &stub);
+ fn get_digest_returns_digest() {
+ let stub = StubRegistry::new(vec![
+ StubTag { registry: "docker.io".into(), image: "nginx".into(), tag: "1.21".into(), digest: "sha256:abc123".into() },
+ ]);
+ assert_eq!(stub.get_digest("docker.io", "nginx", "1.21"), Some("sha256:abc123".to_string()));
}
#[test]
- fn conformance_stub_get_digest_unknown() {
- let stub = StubRegistry::default();
- test_get_digest_returns_none_for_unknown(&stub);
- }
-
- #[test]
- fn conformance_stub_get_digest() {
- let stub = StubRegistry::default();
- test_get_digest_returns_digest(&stub, &stub);
- }
+ fn set_digest_updates_existing() {
+ let stub = StubRegistry::new(vec![
+ StubTag { registry: "docker.io".into(), image: "nginx".into(), tag: "1.21".into(), digest: "sha256:old".into() },
+ ]);
+ stub.set_digest("docker.io", "nginx", "1.21", "sha256:new");
- #[test]
- fn conformance_stub_set_digest() {
- let stub = StubRegistry::default();
- test_set_digest_updates_existing(&stub, &stub);
+ assert_eq!(stub.get_digest("docker.io", "nginx", "1.21"), Some("sha256:new".to_string()));
}
#[cfg(feature = "integration")]