diff --git a/relay-common/src/constants.rs b/relay-common/src/constants.rs index 057629d71dd..14c379f722c 100644 --- a/relay-common/src/constants.rs +++ b/relay-common/src/constants.rs @@ -8,6 +8,8 @@ use std::str::FromStr; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; +use crate::macros::impl_str_serde; + /// The type of an event. /// /// The event type determines how Sentry handles the event and has an impact on processing, rate diff --git a/relay-common/src/lib.rs b/relay-common/src/lib.rs index a42e440c39a..b781a16828c 100644 --- a/relay-common/src/lib.rs +++ b/relay-common/src/lib.rs @@ -5,7 +5,6 @@ html_favicon_url = "https://raw.githubusercontent.com/getsentry/relay/master/artwork/relay-icon.png" )] -#[macro_use] mod macros; mod cell; @@ -19,6 +18,7 @@ mod utils; pub use crate::cell::*; pub use crate::constants::*; pub use crate::glob::*; +pub use crate::macros::*; pub use crate::project::*; pub use crate::retry::*; pub use crate::time::*; diff --git a/relay-common/src/macros.rs b/relay-common/src/macros.rs index 34e29d3fc59..03864fc2333 100644 --- a/relay-common/src/macros.rs +++ b/relay-common/src/macros.rs @@ -17,6 +17,8 @@ macro_rules! impl_str_ser { }; } +pub use impl_str_ser; + /// Helper macro to implement string based deserialization. /// /// If a type implements `FromStr` then this automatically @@ -58,6 +60,8 @@ macro_rules! impl_str_de { }; } +pub use impl_str_de; + /// Helper macro to implement string based serialization and deserialization. /// /// If a type implements `FromStr` and `Display` then this automatically @@ -71,6 +75,8 @@ macro_rules! impl_str_serde { }; } +pub use impl_str_serde; + /// Same as `try` but to be used in functions that return `Box` instead of `Result`. /// /// Useful when calling synchronous (but cheap enough) functions in async code. @@ -84,6 +90,8 @@ macro_rules! tryf { }; } +pub use tryf; + /// A cloning alternative to a `move` closure. /// /// When one needs to use a closure with move semantics one often needs to clone and move some of @@ -127,3 +135,5 @@ macro_rules! clone { move |$($p),+| $body }}; } + +pub use clone; diff --git a/relay-common/src/project.rs b/relay-common/src/project.rs index f389c85c258..e8c502a0608 100644 --- a/relay-common/src/project.rs +++ b/relay-common/src/project.rs @@ -1,6 +1,8 @@ use std::fmt; use std::str::FromStr; +use crate::macros::impl_str_serde; + #[doc(inline)] pub use sentry_types::{ParseProjectIdError, ProjectId}; diff --git a/relay-common/src/utils.rs b/relay-common/src/utils.rs index d8425e51583..1e450af589f 100644 --- a/relay-common/src/utils.rs +++ b/relay-common/src/utils.rs @@ -4,6 +4,8 @@ use std::str; use lazy_static::lazy_static; use regex::Regex; +use crate::macros::impl_str_serde; + lazy_static! { static ref GLOB_RE: Regex = Regex::new(r#"\?|\*\*|\*"#).unwrap(); } diff --git a/relay-general/src/lib.rs b/relay-general/src/lib.rs index 8f6a5b059ef..60b9cf69df8 100644 --- a/relay-general/src/lib.rs +++ b/relay-general/src/lib.rs @@ -12,11 +12,9 @@ #[macro_use] extern crate relay_general_derive; -#[macro_use] mod macros; #[cfg(test)] -#[macro_use] mod testutils; pub mod pii; diff --git a/relay-general/src/macros.rs b/relay-general/src/macros.rs index ae15142d120..32e2f02e34f 100644 --- a/relay-general/src/macros.rs +++ b/relay-general/src/macros.rs @@ -47,13 +47,15 @@ macro_rules! derive_string_meta_structure { }; } +pub(crate) use derive_string_meta_structure; + /// Implements FromStr and Display on a flat/C-like enum such that strings roundtrip correctly and /// all variants can be FromStr'd. /// /// /// Usage: /// -/// ```rust +/// ```ignore /// // derive fail for this or whatever you need. The type must be ZST though. /// struct ValueTypeError; /// @@ -99,3 +101,5 @@ macro_rules! derive_fromstr_and_display { } } } + +pub(crate) use derive_fromstr_and_display; diff --git a/relay-general/src/pii/attachments.rs b/relay-general/src/pii/attachments.rs index f628feb0fe6..7d9bd5aa036 100644 --- a/relay-general/src/pii/attachments.rs +++ b/relay-general/src/pii/attachments.rs @@ -507,6 +507,7 @@ mod tests { use itertools::Itertools; use crate::pii::PiiConfig; + use crate::testutils::assert_eq_bytes_str; use super::*; diff --git a/relay-general/src/pii/builtin.rs b/relay-general/src/pii/builtin.rs index 0ba6ad41d4f..b9b8ee53e88 100644 --- a/relay-general/src/pii/builtin.rs +++ b/relay-general/src/pii/builtin.rs @@ -366,6 +366,7 @@ mod tests { use crate::pii::processor::PiiProcessor; use crate::pii::{Redaction, ReplaceRedaction}; use crate::processor::{process_value, ProcessingState, ValueType}; + use crate::testutils::{assert_eq_dbg, assert_eq_str}; use crate::types::{Annotated, Remark, RemarkType}; use super::{BUILTIN_RULES, BUILTIN_RULES_MAP}; diff --git a/relay-general/src/pii/convert.rs b/relay-general/src/pii/convert.rs index eb942e15395..1014aba0217 100644 --- a/relay-general/src/pii/convert.rs +++ b/relay-general/src/pii/convert.rs @@ -128,6 +128,7 @@ mod tests { use crate::pii::{DataScrubbingConfig, PiiConfig, PiiProcessor}; use crate::processor::{process_value, ProcessingState}; use crate::protocol::Event; + use crate::testutils::{assert_annotated_snapshot, assert_eq_dbg}; use crate::types::FromValue; use super::to_pii_config as to_pii_config_impl; diff --git a/relay-general/src/pii/processor.rs b/relay-general/src/pii/processor.rs index 162d23be1e7..b86e0bce21c 100644 --- a/relay-general/src/pii/processor.rs +++ b/relay-general/src/pii/processor.rs @@ -361,6 +361,7 @@ use { Addr, DebugImage, DebugMeta, Event, ExtraValue, Headers, LogEntry, NativeDebugImage, Request, }, + crate::testutils::assert_annotated_snapshot, crate::types::{Annotated, Object, Value}, }; diff --git a/relay-general/src/processor/attrs.rs b/relay-general/src/processor/attrs.rs index cb34053ee65..50a6f35ea81 100644 --- a/relay-general/src/processor/attrs.rs +++ b/relay-general/src/processor/attrs.rs @@ -6,6 +6,7 @@ use enumset::{EnumSet, EnumSetType}; use failure::Fail; use smallvec::SmallVec; +use crate::macros::derive_fromstr_and_display; use crate::processor::{ProcessValue, SelectorPathItem, SelectorSpec}; use crate::types::Annotated; diff --git a/relay-general/src/processor/chunks.rs b/relay-general/src/processor/chunks.rs index a6b4c2c262c..4651c940abb 100644 --- a/relay-general/src/processor/chunks.rs +++ b/relay-general/src/processor/chunks.rs @@ -174,6 +174,9 @@ where } } +#[cfg(test)] +use crate::testutils::assert_eq_dbg; + #[test] fn test_chunk_split() { let remarks = vec![Remark::with_range( diff --git a/relay-general/src/protocol/breadcrumb.rs b/relay-general/src/protocol/breadcrumb.rs index 2744b7ed611..d2dfa39e96c 100644 --- a/relay-general/src/protocol/breadcrumb.rs +++ b/relay-general/src/protocol/breadcrumb.rs @@ -121,6 +121,9 @@ pub struct Breadcrumb { pub other: Object, } +#[cfg(test)] +use crate::testutils::{assert_eq_dbg, assert_eq_str}; + #[test] fn test_breadcrumb_roundtrip() { use crate::types::Map; diff --git a/relay-general/src/protocol/client_report.rs b/relay-general/src/protocol/client_report.rs index 3d3b3ef6b89..414bf9fc1c2 100644 --- a/relay-general/src/protocol/client_report.rs +++ b/relay-general/src/protocol/client_report.rs @@ -42,6 +42,8 @@ impl ClientReport { mod tests { use super::*; + use crate::testutils::{assert_eq_dbg, assert_eq_str}; + #[test] fn test_client_report_roundtrip() { let json = r#"{ diff --git a/relay-general/src/protocol/clientsdk.rs b/relay-general/src/protocol/clientsdk.rs index fb42e5a9665..afe5293c5d6 100644 --- a/relay-general/src/protocol/clientsdk.rs +++ b/relay-general/src/protocol/clientsdk.rs @@ -64,6 +64,9 @@ pub struct ClientSdkInfo { pub other: Object, } +#[cfg(test)] +use crate::testutils::{assert_eq_dbg, assert_eq_str}; + #[test] fn test_client_sdk_roundtrip() { use crate::types::Map; diff --git a/relay-general/src/protocol/contexts.rs b/relay-general/src/protocol/contexts.rs index 4b96f16a85d..2be2937a45b 100644 --- a/relay-general/src/protocol/contexts.rs +++ b/relay-general/src/protocol/contexts.rs @@ -731,6 +731,9 @@ impl FromValue for Contexts { } } +#[cfg(test)] +use crate::testutils::{assert_eq_dbg, assert_eq_str}; + #[test] fn test_device_context_roundtrip() { let json = r#"{ diff --git a/relay-general/src/protocol/debugmeta.rs b/relay-general/src/protocol/debugmeta.rs index 3db99e47d60..b1932601dbb 100644 --- a/relay-general/src/protocol/debugmeta.rs +++ b/relay-general/src/protocol/debugmeta.rs @@ -481,7 +481,10 @@ pub struct DebugMeta { } #[cfg(test)] -use crate::types::Map; +use { + crate::testutils::{assert_eq_dbg, assert_eq_str}, + crate::types::Map, +}; #[test] fn test_debug_image_proguard_roundtrip() { diff --git a/relay-general/src/protocol/event.rs b/relay-general/src/protocol/event.rs index 1dff95f9a6e..93323af1bd4 100644 --- a/relay-general/src/protocol/event.rs +++ b/relay-general/src/protocol/event.rs @@ -8,6 +8,7 @@ use schemars::schema::Schema; use serde::{Serialize, Serializer}; +use crate::macros::derive_string_meta_structure; use crate::processor::ProcessValue; use crate::protocol::{ Breadcrumb, Breakdowns, ClientSdkInfo, Contexts, Csp, DebugMeta, Exception, ExpectCt, @@ -532,6 +533,9 @@ pub struct Event { pub other: Object, } +#[cfg(test)] +use crate::testutils::{assert_eq_dbg, assert_eq_str}; + #[test] fn test_event_roundtrip() { use chrono::{TimeZone, Utc}; diff --git a/relay-general/src/protocol/exception.rs b/relay-general/src/protocol/exception.rs index bce8757c220..1f5f5a846b8 100644 --- a/relay-general/src/protocol/exception.rs +++ b/relay-general/src/protocol/exception.rs @@ -68,6 +68,9 @@ pub struct Exception { pub other: Object, } +#[cfg(test)] +use crate::testutils::{assert_eq_dbg, assert_eq_str}; + #[test] fn test_exception_roundtrip() { use crate::types::Map; diff --git a/relay-general/src/protocol/fingerprint.rs b/relay-general/src/protocol/fingerprint.rs index fd4c10d8001..93e7c1d8a07 100644 --- a/relay-general/src/protocol/fingerprint.rs +++ b/relay-general/src/protocol/fingerprint.rs @@ -114,6 +114,9 @@ impl IntoValue for Fingerprint { // Fingerprints must not be trimmed. impl ProcessValue for Fingerprint {} +#[cfg(test)] +use crate::testutils::assert_eq_dbg; + #[test] fn test_fingerprint_string() { assert_eq_dbg!( diff --git a/relay-general/src/protocol/logentry.rs b/relay-general/src/protocol/logentry.rs index 8bbdc5278a0..7dd005bc909 100644 --- a/relay-general/src/protocol/logentry.rs +++ b/relay-general/src/protocol/logentry.rs @@ -131,6 +131,9 @@ impl FromValue for LogEntry { } } +#[cfg(test)] +use crate::testutils::{assert_eq_dbg, assert_eq_str}; + #[test] fn test_logentry_roundtrip() { let json = r#"{ diff --git a/relay-general/src/protocol/measurements.rs b/relay-general/src/protocol/measurements.rs index 2072155f694..04d9d44e9dc 100644 --- a/relay-general/src/protocol/measurements.rs +++ b/relay-general/src/protocol/measurements.rs @@ -134,6 +134,9 @@ fn is_valid_measurement_name(name: &str) -> bool { .all(|c| matches!(c, 'a'..='z' | 'A'..='Z' | '0'..='9' | '-' | '_' | '.')) } +#[cfg(test)] +use crate::testutils::{assert_eq_dbg, assert_eq_str}; + #[test] fn test_measurements_serialization() { use crate::protocol::Event; diff --git a/relay-general/src/protocol/mechanism.rs b/relay-general/src/protocol/mechanism.rs index 095c8973c2c..ddebb404f57 100644 --- a/relay-general/src/protocol/mechanism.rs +++ b/relay-general/src/protocol/mechanism.rs @@ -256,6 +256,9 @@ impl FromValue for Mechanism { } } +#[cfg(test)] +use crate::testutils::{assert_eq_dbg, assert_eq_str}; + #[test] fn test_mechanism_roundtrip() { use crate::types::Map; diff --git a/relay-general/src/protocol/request.rs b/relay-general/src/protocol/request.rs index 8946fc037bf..e09b86ace6a 100644 --- a/relay-general/src/protocol/request.rs +++ b/relay-general/src/protocol/request.rs @@ -500,6 +500,9 @@ pub struct Request { pub other: Object, } +#[cfg(test)] +use crate::testutils::{assert_eq_dbg, assert_eq_str}; + #[test] fn test_header_normalization() { let json = r#"{ diff --git a/relay-general/src/protocol/security_report.rs b/relay-general/src/protocol/security_report.rs index 68ac69763d5..e37ea17ae1c 100644 --- a/relay-general/src/protocol/security_report.rs +++ b/relay-general/src/protocol/security_report.rs @@ -11,6 +11,7 @@ use serde::de::{Error, IgnoredAny}; use serde::{Deserialize, Serialize}; use url::Url; +use crate::macros::derive_fromstr_and_display; use crate::protocol::{ Event, HeaderName, HeaderValue, Headers, LogEntry, PairList, Request, TagEntry, Tags, }; @@ -1083,6 +1084,8 @@ impl SecurityReportType { mod tests { use super::*; + use crate::testutils::assert_annotated_snapshot; + #[test] fn test_unsplit_uri() { assert_eq!(unsplit_uri("", ""), ""); diff --git a/relay-general/src/protocol/session.rs b/relay-general/src/protocol/session.rs index 8898e742b0b..c0a1802a9bd 100644 --- a/relay-general/src/protocol/session.rs +++ b/relay-general/src/protocol/session.rs @@ -5,6 +5,7 @@ use failure::Fail; use serde::{Deserialize, Serialize}; use uuid::Uuid; +use crate::macros::derive_fromstr_and_display; use crate::protocol::IpAddr; /// The type of session event we're dealing with. @@ -295,6 +296,8 @@ impl SessionAggregates { mod tests { use super::*; + use crate::testutils::{assert_eq_dbg, assert_eq_str}; + #[test] fn test_session_default_values() { let json = r#"{ diff --git a/relay-general/src/protocol/span.rs b/relay-general/src/protocol/span.rs index dcb57e16c51..8e08c2514e8 100644 --- a/relay-general/src/protocol/span.rs +++ b/relay-general/src/protocol/span.rs @@ -56,6 +56,7 @@ pub struct Span { #[cfg(test)] mod tests { use super::*; + use crate::testutils::{assert_eq_dbg, assert_eq_str}; use chrono::{TimeZone, Utc}; #[test] diff --git a/relay-general/src/protocol/stacktrace.rs b/relay-general/src/protocol/stacktrace.rs index 032eaa39f60..36b99c23164 100644 --- a/relay-general/src/protocol/stacktrace.rs +++ b/relay-general/src/protocol/stacktrace.rs @@ -366,6 +366,9 @@ impl From for RawStacktrace { } } +#[cfg(test)] +use crate::testutils::{assert_eq_dbg, assert_eq_str}; + #[test] fn test_frame_roundtrip() { let json = r#"{ diff --git a/relay-general/src/protocol/tags.rs b/relay-general/src/protocol/tags.rs index ddd9a81ae75..1f46deee63b 100644 --- a/relay-general/src/protocol/tags.rs +++ b/relay-general/src/protocol/tags.rs @@ -72,6 +72,9 @@ impl std::ops::DerefMut for Tags { } } +#[cfg(test)] +use crate::testutils::{assert_eq_dbg, assert_eq_str}; + #[test] fn test_tags_from_object() { let json = r#"{ diff --git a/relay-general/src/protocol/templateinfo.rs b/relay-general/src/protocol/templateinfo.rs index d9a770ca344..d7f9825f647 100644 --- a/relay-general/src/protocol/templateinfo.rs +++ b/relay-general/src/protocol/templateinfo.rs @@ -32,6 +32,9 @@ pub struct TemplateInfo { pub other: Object, } +#[cfg(test)] +use crate::testutils::{assert_eq_dbg, assert_eq_str}; + #[test] fn test_template_roundtrip() { use crate::types::Map; diff --git a/relay-general/src/protocol/thread.rs b/relay-general/src/protocol/thread.rs index 4c5567cd5e3..18a0ecba453 100644 --- a/relay-general/src/protocol/thread.rs +++ b/relay-general/src/protocol/thread.rs @@ -127,6 +127,9 @@ pub struct Thread { pub other: Object, } +#[cfg(test)] +use crate::testutils::{assert_eq_dbg, assert_eq_str}; + #[test] fn test_thread_id() { assert_eq_dbg!( diff --git a/relay-general/src/protocol/types.rs b/relay-general/src/protocol/types.rs index aa4ccfcc28b..6c7dc7ca262 100644 --- a/relay-general/src/protocol/types.rs +++ b/relay-general/src/protocol/types.rs @@ -1101,6 +1101,9 @@ impl schemars::JsonSchema for Timestamp { } } +#[cfg(test)] +use crate::testutils::{assert_eq_dbg, assert_eq_str}; + #[test] fn test_values_serialization() { let value = Annotated::new(Values { diff --git a/relay-general/src/protocol/user.rs b/relay-general/src/protocol/user.rs index f12d2a6e8f9..001bbb1a637 100644 --- a/relay-general/src/protocol/user.rs +++ b/relay-general/src/protocol/user.rs @@ -78,6 +78,9 @@ pub struct User { pub other: Object, } +#[cfg(test)] +use crate::testutils::{assert_eq_dbg, assert_eq_str}; + #[test] fn test_geo_roundtrip() { use crate::types::Map; diff --git a/relay-general/src/store/clock_drift.rs b/relay-general/src/store/clock_drift.rs index dc0fa0c2671..54c6fc79259 100644 --- a/relay-general/src/store/clock_drift.rs +++ b/relay-general/src/store/clock_drift.rs @@ -21,7 +21,7 @@ impl ClockCorrection { } fn at_least(self, lower_bound: Duration) -> Option { - if self.drift.num_seconds().abs() as u64 >= lower_bound.as_secs() { + if self.drift.num_seconds().unsigned_abs() >= lower_bound.as_secs() { Some(self) } else { None diff --git a/relay-general/src/store/event_error.rs b/relay-general/src/store/event_error.rs index ef323750d2e..415a8356792 100644 --- a/relay-general/src/store/event_error.rs +++ b/relay-general/src/store/event_error.rs @@ -63,6 +63,7 @@ impl Processor for EmitEventErrors { #[cfg(test)] use { crate::processor::process_value, + crate::testutils::assert_eq_dbg, crate::types::{ErrorKind, Object, Value}, }; diff --git a/relay-general/src/store/normalize.rs b/relay-general/src/store/normalize.rs index f342eb88d9b..c0f1e6d0e06 100644 --- a/relay-general/src/store/normalize.rs +++ b/relay-general/src/store/normalize.rs @@ -719,6 +719,7 @@ impl<'a> Processor for NormalizeProcessor<'a> { use crate::{ processor::process_value, protocol::{PairList, TagEntry}, + testutils::{assert_eq_dbg, get_path, get_value}, }; #[cfg(test)] diff --git a/relay-general/src/store/normalize/breakdowns.rs b/relay-general/src/store/normalize/breakdowns.rs index c492e1717ec..dc7619e45e2 100644 --- a/relay-general/src/store/normalize/breakdowns.rs +++ b/relay-general/src/store/normalize/breakdowns.rs @@ -235,6 +235,7 @@ pub fn normalize_breakdowns(event: &mut Event, breakdowns_config: &BreakdownsCon mod tests { use super::*; use crate::protocol::{EventType, Span, SpanId, SpanStatus, TraceId}; + use crate::testutils::assert_eq_dbg; use crate::types::Object; use chrono::{TimeZone, Utc}; diff --git a/relay-general/src/store/normalize/contexts.rs b/relay-general/src/store/normalize/contexts.rs index 81790bebcba..f6b3a9134ef 100644 --- a/relay-general/src/store/normalize/contexts.rs +++ b/relay-general/src/store/normalize/contexts.rs @@ -173,7 +173,7 @@ pub fn normalize_context(context: &mut Context) { } #[cfg(test)] -use crate::protocol::LenientString; +use {crate::protocol::LenientString, crate::testutils::assert_eq_dbg}; #[test] fn test_dotnet_framework_48_without_build_id() { diff --git a/relay-general/src/store/normalize/logentry.rs b/relay-general/src/store/normalize/logentry.rs index 3091d0a66be..263daf4fa21 100644 --- a/relay-general/src/store/normalize/logentry.rs +++ b/relay-general/src/store/normalize/logentry.rs @@ -81,7 +81,7 @@ pub fn normalize_logentry(logentry: &mut LogEntry, meta: &mut Meta) -> Processin } #[cfg(test)] -use crate::types::Object; +use {crate::testutils::assert_eq_dbg, crate::types::Object}; #[test] fn test_format_python() { diff --git a/relay-general/src/store/normalize/request.rs b/relay-general/src/store/normalize/request.rs index baa094f7e32..3bd249a4867 100644 --- a/relay-general/src/store/normalize/request.rs +++ b/relay-general/src/store/normalize/request.rs @@ -189,10 +189,7 @@ pub fn normalize_request(request: &mut Request) -> ProcessingResult { } #[cfg(test)] -use crate::protocol::PairList; - -#[cfg(test)] -use crate::types::Object; +use {crate::protocol::PairList, crate::testutils::assert_eq_dbg, crate::types::Object}; #[test] fn test_url_truncation() { diff --git a/relay-general/src/store/normalize/user_agent.rs b/relay-general/src/store/normalize/user_agent.rs index d3235df24b6..b7ad48a4750 100644 --- a/relay-general/src/store/normalize/user_agent.rs +++ b/relay-general/src/store/normalize/user_agent.rs @@ -99,6 +99,7 @@ fn get_version( mod tests { use super::*; use crate::testutils; + use crate::testutils::assert_annotated_snapshot; const GOOD_UA: &str = "Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19"; diff --git a/relay-general/src/store/remove_other.rs b/relay-general/src/store/remove_other.rs index 0333028bb2f..c7169f524d8 100644 --- a/relay-general/src/store/remove_other.rs +++ b/relay-general/src/store/remove_other.rs @@ -73,7 +73,11 @@ impl Processor for RemoveOtherProcessor { } #[cfg(test)] -use {crate::processor::process_value, crate::protocol::ContextInner}; +use { + crate::processor::process_value, + crate::protocol::ContextInner, + crate::testutils::{assert_eq_dbg, get_value}, +}; #[test] fn test_remove_legacy_attributes() { diff --git a/relay-general/src/store/schema.rs b/relay-general/src/store/schema.rs index 3e30b7c2aa0..ab34fc01053 100644 --- a/relay-general/src/store/schema.rs +++ b/relay-general/src/store/schema.rs @@ -105,6 +105,7 @@ fn verify_value_characters( mod tests { use super::SchemaProcessor; use crate::processor::{process_value, ProcessingState}; + use crate::testutils::assert_eq_dbg; use crate::types::{Annotated, Array, Error, Object}; fn assert_nonempty_base() diff --git a/relay-general/src/store/transactions.rs b/relay-general/src/store/transactions.rs index 359127a12cb..f2e27c6fe14 100644 --- a/relay-general/src/store/transactions.rs +++ b/relay-general/src/store/transactions.rs @@ -184,6 +184,7 @@ mod tests { use crate::processor::process_value; use crate::protocol::{Contexts, SpanId, TraceContext, TraceId}; + use crate::testutils::{assert_annotated_snapshot, assert_eq_dbg}; use crate::types::Object; fn new_test_event() -> Annotated { diff --git a/relay-general/src/store/trimming.rs b/relay-general/src/store/trimming.rs index f0e637a3455..52ce9f61026 100644 --- a/relay-general/src/store/trimming.rs +++ b/relay-general/src/store/trimming.rs @@ -388,6 +388,9 @@ fn slim_frame_data(frames: &mut Array, frame_allowance: usize) { } } +#[cfg(test)] +use crate::testutils::{assert_eq_dbg, assert_eq_str}; + #[test] fn test_string_trimming() { use crate::processor::MaxChars; diff --git a/relay-general/src/testutils.rs b/relay-general/src/testutils.rs index 625bc2bf314..3dcc97cfd5f 100644 --- a/relay-general/src/testutils.rs +++ b/relay-general/src/testutils.rs @@ -20,6 +20,8 @@ macro_rules! assert_eq_str { }; } +pub(crate) use assert_eq_str; + macro_rules! assert_eq_bytes_str { ($left:expr, $right:expr) => { match (&$left, &$right) { @@ -37,6 +39,8 @@ macro_rules! assert_eq_bytes_str { }; } +pub(crate) use assert_eq_bytes_str; + macro_rules! assert_eq_dbg { ($left:expr, $right:expr) => { match (&$left, &$right) { @@ -54,6 +58,8 @@ macro_rules! assert_eq_dbg { }; } +pub(crate) use assert_eq_dbg; + macro_rules! assert_annotated_snapshot { ($value:expr, @$snapshot:literal) => { ::insta::assert_snapshot!( @@ -92,6 +98,8 @@ macro_rules! assert_annotated_snapshot { }; } +pub(crate) use assert_annotated_snapshot; + /// Returns `&Annotated` for the annotated value at the given path. macro_rules! get_path { (@access $root:ident,) => {}; @@ -113,6 +121,8 @@ macro_rules! get_path { }}; } +pub(crate) use get_path; + /// Returns `Option<&V>` for the value at the given path. macro_rules! get_value { (@access $root:ident,) => {}; @@ -134,6 +144,8 @@ macro_rules! get_value { }}; } +pub(crate) use get_value; + #[cfg(feature = "uaparser")] /// Creates an Event with the specified user agent. pub(super) fn get_event_with_user_agent(user_agent: &str) -> Event { diff --git a/relay-general/src/types/annotated.rs b/relay-general/src/types/annotated.rs index 89ab5af77c3..8589be52dcd 100644 --- a/relay-general/src/types/annotated.rs +++ b/relay-general/src/types/annotated.rs @@ -438,6 +438,9 @@ where } } +#[cfg(test)] +use crate::testutils::assert_eq_str; + #[test] fn test_annotated_deserialize_with_meta() { use crate::types::ErrorKind; diff --git a/relay-general/src/types/impls.rs b/relay-general/src/types/impls.rs index 50bba6f3c5a..d8b15729cac 100644 --- a/relay-general/src/types/impls.rs +++ b/relay-general/src/types/impls.rs @@ -2,6 +2,7 @@ use serde::ser::{SerializeMap, SerializeSeq}; use serde::{Serialize, Serializer}; use uuid::Uuid; +use crate::macros::derive_string_meta_structure; use crate::types::{ Annotated, Array, Empty, Error, FromValue, IntoValue, Map, Meta, MetaMap, MetaTree, Object, SkipSerialization, Value, @@ -585,6 +586,9 @@ tuple_meta_structure!(10, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10); tuple_meta_structure!(11, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11); tuple_meta_structure!(12, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12); +#[cfg(test)] +use crate::testutils::{assert_eq_dbg, assert_eq_str}; + #[test] fn test_unsigned_integers() { assert_eq_dbg!(Annotated::new(1u64), Annotated::from_json("1").unwrap(),); diff --git a/relay-server/src/endpoints/common.rs b/relay-server/src/endpoints/common.rs index 4e471b89ef5..e3eecb4782e 100644 --- a/relay-server/src/endpoints/common.rs +++ b/relay-server/src/endpoints/common.rs @@ -1,6 +1,7 @@ //! Common facilities for ingesting events through store-like endpoints. use std::cell::RefCell; +use std::fmt::Write; use std::rc::Rc; use actix::prelude::*; @@ -472,11 +473,12 @@ pub fn normpath(route: &str) -> String { let mut pattern = String::new(); for (i, segment) in route.trim_matches('/').split('/').enumerate() { // Apparently the leading slash needs to be explicit and cannot be part of a pattern - pattern.push_str(&format!( + let _ = write!( + pattern, "/{{multislash{i}:/*}}{segment}", i = i, segment = segment - )); + ); } if route.ends_with('/') {