diff --git a/Cargo.lock b/Cargo.lock index 20877964..35d020f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -142,6 +142,7 @@ dependencies = [ "serde_json", "serde_with", "tempfile", + "url", ] [[package]] @@ -172,6 +173,15 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + [[package]] name = "hashbrown" version = "0.12.3" @@ -219,6 +229,16 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "indexmap" version = "1.9.3" @@ -304,6 +324,12 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + [[package]] name = "powerfmt" version = "0.2.0" @@ -478,12 +504,53 @@ dependencies = [ "time-core", ] +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "url" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + [[package]] name = "wasm-bindgen" version = "0.2.91" diff --git a/packages/dns-test/Cargo.toml b/packages/dns-test/Cargo.toml index 0851b3e4..20b13d33 100644 --- a/packages/dns-test/Cargo.toml +++ b/packages/dns-test/Cargo.toml @@ -11,6 +11,7 @@ serde = { version = "1.0.196", features = ["derive"] } serde_json = "1.0.113" serde_with = "3.6.1" tempfile = "3.9.0" +url = "2.5.0" [lib] doctest = false diff --git a/packages/dns-test/src/container.rs b/packages/dns-test/src/container.rs index 449f81d8..92550114 100644 --- a/packages/dns-test/src/container.rs +++ b/packages/dns-test/src/container.rs @@ -37,20 +37,20 @@ impl Container { .arg(&image_tag) .arg(docker_build_dir); - let srcdir = if let Implementation::Hickory { url } = implementation { - Some(url) + let repo = if let Implementation::Hickory(repo) = implementation { + Some(repo) } else { None }; implementation.once().call_once(|| { - if let Some(srcdir) = srcdir { + if let Some(repo) = repo { let mut cp_r = Command::new("git"); cp_r.args([ "clone", "--depth", "1", - srcdir, + repo.as_str(), &docker_build_dir.join("src").display().to_string(), ]); diff --git a/packages/dns-test/src/lib.rs b/packages/dns-test/src/lib.rs index 82d90851..75ea0f58 100644 --- a/packages/dns-test/src/lib.rs +++ b/packages/dns-test/src/lib.rs @@ -1,8 +1,12 @@ //! A test framework for all things DNS use core::fmt; +use std::borrow::Cow; +use std::path::Path; use std::sync::Once; +use url::Url; + pub use crate::container::Network; pub use crate::fqdn::FQDN; pub use crate::resolver::Resolver; @@ -24,7 +28,33 @@ pub mod zone_file; #[derive(Clone)] pub enum Implementation { Unbound, - Hickory { url: String }, + Hickory(Repository<'static>), +} + +#[derive(Clone)] +pub struct Repository<'a> { + inner: Cow<'a, str>, +} + +impl Repository<'_> { + fn as_str(&self) -> &str { + &self.inner + } +} + +/// checks that `input` looks like a valid repository which can be either local or remote +/// +/// # Panics +/// +/// this function panics if `input` is not a local `Path` that exists or a well-formed URL +#[allow(non_snake_case)] +pub fn Repository(input: impl Into>) -> Repository<'static> { + let input = input.into(); + assert!( + Path::new(&*input).exists() || Url::parse(&input).is_ok(), + "{input} is not a valid repository" + ); + Repository { inner: input } } impl Implementation { @@ -74,9 +104,7 @@ pub fn subject() -> Implementation { if subject.starts_with("hickory") { if let Some(url) = subject.strip_prefix("hickory ") { - Implementation::Hickory { - url: url.to_string(), - } + Implementation::Hickory(Repository(url.to_string())) } else { panic!("the syntax of DNS_TEST_SUBJECT is 'hickory $URL', e.g. 'hickory /tmp/hickory' or 'hickory https://github.com/owner/repo'") }