From ddcb56de0a2ea8f6326257c07c9199f8214608e4 Mon Sep 17 00:00:00 2001 From: paullegranddc Date: Mon, 1 Jul 2024 15:38:57 +0200 Subject: [PATCH] Add test verifying that this no longer returns a null pointer in case of valid path --- ddcommon-ffi/src/endpoint.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/ddcommon-ffi/src/endpoint.rs b/ddcommon-ffi/src/endpoint.rs index 13955a9d8..c6a15375d 100644 --- a/ddcommon-ffi/src/endpoint.rs +++ b/ddcommon-ffi/src/endpoint.rs @@ -51,3 +51,28 @@ pub extern "C" fn ddog_endpoint_from_api_key_and_site( #[no_mangle] pub extern "C" fn ddog_endpoint_drop(_: Box) {} + +#[cfg(test)] +mod tests { + use crate::CharSlice; + + use super::ddog_endpoint_from_url; + + #[test] + fn test_ddog_endpoint_from_url() { + let cases = [ + ("", false), + ("http:// /hey", false), + ("file://", false), + ("http://localhost:8383/hello", true), + ("file:/// file / with/weird chars 🤡", true), + ("file://./", true), + ("unix://./", true), + ]; + + for (input, expected) in cases { + let actual = ddog_endpoint_from_url(CharSlice::from(input)).is_some(); + assert_eq!(actual, expected); + } + } +}