From d19f948f7b379d50e0ff5f82b3e7a97d4ea4ef2c Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 25 Sep 2023 12:48:28 -0400 Subject: [PATCH] container: Add more tests for image reference - Cover containers-storage and oci-archive too - Test that we can reserialize back into the same string --- lib/src/container/mod.rs | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/lib/src/container/mod.rs b/lib/src/container/mod.rs index bc172d39..a1b36e8b 100644 --- a/lib/src/container/mod.rs +++ b/lib/src/container/mod.rs @@ -517,13 +517,39 @@ mod tests { panic!("Should fail to parse: {}", v) } } - let ir: ImageReference = "oci:somedir".try_into().unwrap(); - assert_eq!(ir.transport, Transport::OciDir); - assert_eq!(ir.name, "somedir"); - - let ir: ImageReference = "dir:/some/dir/blah".try_into().unwrap(); - assert_eq!(ir.transport, Transport::Dir); - assert_eq!(ir.name, "/some/dir/blah"); + struct Case { + s: &'static str, + transport: Transport, + name: &'static str, + } + for case in [ + Case { + s: "oci:somedir", + transport: Transport::OciDir, + name: "somedir", + }, + Case { + s: "dir:/some/dir/blah", + transport: Transport::Dir, + name: "/some/dir/blah", + }, + Case { + s: "oci-archive:/path/to/foo.ociarchive", + transport: Transport::OciArchive, + name: "/path/to/foo.ociarchive", + }, + Case { + s: "containers-storage:localhost/someimage:blah", + transport: Transport::ContainerStorage, + name: "localhost/someimage:blah", + }, + ] { + let ir: ImageReference = case.s.try_into().unwrap(); + assert_eq!(ir.transport, case.transport); + assert_eq!(ir.name, case.name); + let reserialized = ir.to_string(); + assert_eq!(case.s, reserialized.as_str()); + } } #[test]