From 2a12e251f2591b7785d7a921364f125d2e9c1e6e Mon Sep 17 00:00:00 2001 From: mdecimus Date: Fri, 2 Aug 2024 09:16:57 +0200 Subject: [PATCH] Fixed tests --- Cargo.lock | 124 +-------------- crates/common/src/tracing/journald.rs | 33 ---- crates/jmap-proto/src/response/references.rs | 9 +- crates/trc/src/fmt.rs | 11 +- crates/trc/src/lib.rs | 156 +++++++++---------- crates/utils/Cargo.toml | 1 - tests/Cargo.toml | 1 - 7 files changed, 97 insertions(+), 238 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 694e5330..9502cef9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1964,8 +1964,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "531e46835a22af56d1e3b66f04844bed63158bc094a628bec1d321d9b4c44bf2" dependencies = [ "bit-set", - "regex-automata 0.4.7", - "regex-syntax 0.8.4", + "regex-automata", + "regex-syntax", ] [[package]] @@ -3311,7 +3311,7 @@ dependencies = [ "lalrpop-util", "petgraph", "regex", - "regex-syntax 0.8.4", + "regex-syntax", "string_cache", "term", "tiny-keccak", @@ -3325,7 +3325,7 @@ version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "507460a910eb7b32ee961886ff48539633b788a36b65692b95f225b844c82553" dependencies = [ - "regex-automata 0.4.7", + "regex-automata", ] [[package]] @@ -3650,15 +3650,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" -[[package]] -name = "matchers" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" -dependencies = [ - "regex-automata 0.1.10", -] - [[package]] name = "matchit" version = "0.7.3" @@ -3940,16 +3931,6 @@ dependencies = [ "minimal-lexical", ] -[[package]] -name = "nu-ansi-term" -version = "0.46.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" -dependencies = [ - "overload", - "winapi", -] - [[package]] name = "num-bigint" version = "0.4.6" @@ -4206,12 +4187,6 @@ dependencies = [ "hashbrown 0.14.5", ] -[[package]] -name = "overload" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" - [[package]] name = "p256" version = "0.13.2" @@ -5002,17 +4977,8 @@ checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.7", - "regex-syntax 0.8.4", -] - -[[package]] -name = "regex-automata" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" -dependencies = [ - "regex-syntax 0.6.29", + "regex-automata", + "regex-syntax", ] [[package]] @@ -5023,15 +4989,9 @@ checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.8.4", + "regex-syntax", ] -[[package]] -name = "regex-syntax" -version = "0.6.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" - [[package]] name = "regex-syntax" version = "0.8.4" @@ -5756,7 +5716,7 @@ dependencies = [ "rand", "rand_core", "regex", - "regex-syntax 0.8.4", + "regex-syntax", "ripemd", "rsa", "sha1collisiondetection", @@ -5933,15 +5893,6 @@ dependencies = [ "digest 0.10.7", ] -[[package]] -name = "sharded-slab" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" -dependencies = [ - "lazy_static", -] - [[package]] name = "shlex" version = "1.3.0" @@ -6431,7 +6382,6 @@ dependencies = [ "store", "tokio", "tokio-rustls 0.26.0", - "tracing-subscriber", "trc", "utils", ] @@ -6456,16 +6406,6 @@ dependencies = [ "syn 2.0.72", ] -[[package]] -name = "thread_local" -version = "1.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" -dependencies = [ - "cfg-if", - "once_cell", -] - [[package]] name = "time" version = "0.3.36" @@ -6803,47 +6743,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", - "valuable", -] - -[[package]] -name = "tracing-journald" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba316a74e8fc3c3896a850dba2375928a9fa171b085ecddfc7c054d39970f3fd" -dependencies = [ - "libc", - "tracing-core", - "tracing-subscriber", -] - -[[package]] -name = "tracing-log" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" -dependencies = [ - "log", - "once_cell", - "tracing-core", -] - -[[package]] -name = "tracing-subscriber" -version = "0.3.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" -dependencies = [ - "matchers", - "nu-ansi-term", - "once_cell", - "regex", - "sharded-slab", - "smallvec", - "thread_local", - "tracing", - "tracing-core", - "tracing-log", ] [[package]] @@ -7120,7 +7019,6 @@ dependencies = [ "smtp-proto", "tokio", "tokio-rustls 0.26.0", - "tracing-journald", "trc", "webpki-roots 0.26.3", "x509-parser 0.16.0", @@ -7135,12 +7033,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "valuable" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" - [[package]] name = "vcpkg" version = "0.2.15" diff --git a/crates/common/src/tracing/journald.rs b/crates/common/src/tracing/journald.rs index cae2f99a..a6bba014 100644 --- a/crates/common/src/tracing/journald.rs +++ b/crates/common/src/tracing/journald.rs @@ -204,34 +204,6 @@ impl Subscriber { /// Sets how [`tracing_core::Level`]s are mapped to [journald priorities](Priority). /// - /// # Examples - /// - /// ```rust - /// use tracing_journald::{Priority, PriorityMappings}; - /// use tracing_subscriber::prelude::*; - /// use tracing::error; - /// - /// let registry = tracing_subscriber::registry(); - /// match tracing_journald::subscriber() { - /// Ok(subscriber) => { - /// registry.with( - /// subscriber - /// // We can tweak the mappings between the trace level and - /// // the journal priorities. - /// .with_priority_mappings(PriorityMappings { - /// info: Priority::Informational, - /// ..PriorityMappings::new() - /// }), - /// ); - /// } - /// // journald is typically available on Linux systems, but nowhere else. Portable software - /// // should handle its absence gracefully. - /// Err(e) => { - /// registry.init(); - /// error!("couldn't connect to journald: {}", e); - /// } - /// } - /// ``` pub fn with_priority_mappings(mut self, mappings: PriorityMappings) -> Self { self.priority_mappings = mappings; self @@ -311,11 +283,6 @@ impl Subscriber { impl PriorityMappings { /// Returns the default priority mappings: /// - /// - [`tracing::Level::ERROR`]: [`Priority::Error`] (3) - /// - [`tracing::Level::WARN`]: [`Priority::Warning`] (4) - /// - [`tracing::Level::INFO`]: [`Priority::Notice`] (5) - /// - [`tracing::Level::DEBUG`]: [`Priority::Informational`] (6) - /// - [`tracing::Level::TRACE`]: [`Priority::Debug`] (7) pub fn new() -> PriorityMappings { Self { error: Priority::Error, diff --git a/crates/jmap-proto/src/response/references.rs b/crates/jmap-proto/src/response/references.rs index eacae954..28ecffe4 100644 --- a/crates/jmap-proto/src/response/references.rs +++ b/crates/jmap-proto/src/response/references.rs @@ -694,10 +694,11 @@ mod tests { ), Err(err) => { assert_eq!(test_num, 3); - assert!(matches!( - err.value(trc::Key::Type).and_then(|v| v.as_str()).unwrap(), - "invalidArguments" - )); + assert!( + err.matches(trc::EventType::Jmap(trc::JmapEvent::InvalidArguments)), + "{:?}", + err + ); continue; } } diff --git a/crates/trc/src/fmt.rs b/crates/trc/src/fmt.rs index b21b179d..e1bd4d9b 100644 --- a/crates/trc/src/fmt.rs +++ b/crates/trc/src/fmt.rs @@ -336,15 +336,16 @@ mod tests { let mut names = Vec::with_capacity(100); for event in EventType::variants() { - names.push(event.name()); + names.push((event.name(), event.description(), event.level().as_str())); assert_eq!(EventType::try_parse(event.name()).unwrap(), event); } - // sort - names.sort(); + // sort by name + names.sort_by(|a, b| a.0.cmp(b.0)); - for name in names { - println!("{:?},", name); + for (name, description, level) in names { + //println!("{:?},", name); + println!("|`{name}`|{description}|`{level}`|") } } } diff --git a/crates/trc/src/lib.rs b/crates/trc/src/lib.rs index a7b6b3e3..be3aadaa 100644 --- a/crates/trc/src/lib.rs +++ b/crates/trc/src/lib.rs @@ -72,96 +72,96 @@ pub enum Value { #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)] #[camel_names] pub enum Key { + AccountId, + Attempt, + BlobId, #[default] CausedBy, - Reason, - Details, - Query, - Result, - Parameters, - Type, - Id, - Code, - Key, - Value, - Size, - Status, - Total, - Protocol, - Property, - Path, - Url, - Used, - Name, - OldName, - DocumentId, - Collection, - AccountId, - QueueId, - SpanId, - ReportId, - MessageId, - MailboxId, ChangeId, - BlobId, - ListenerId, - Hostname, - ValidFrom, - ValidTo, - Origin, - Expected, - Renewal, - Attempt, - NextRetry, - NextDsn, - LocalIp, - LocalPort, - RemoteIp, - RemotePort, - Limit, - Tls, - Version, Cipher, - Duration, - Count, - Spam, - MinLearns, - SpamLearns, - HamLearns, - MinBalance, + Code, + Collection, Contents, - Due, - NextRenewal, - Expires, - From, - To, - Interval, - Strict, - Domain, - Policy, - Elapsed, - RangeFrom, - RangeTo, + Count, + Date, + Details, + DkimFail, + DkimNone, + DkimPass, + DmarcNone, DmarcPass, DmarcQuarantine, DmarcReject, - DmarcNone, - DkimPass, - DkimFail, - DkimNone, - SpfPass, - SpfFail, - SpfNone, + DocumentId, + Domain, + Due, + Duration, + Elapsed, + Expected, + Expires, + From, + HamLearns, + Hostname, + Id, + Interval, + Key, + Limit, + ListenerId, + LocalIp, + LocalPort, + MailboxId, + MessageId, + MinBalance, + MinLearns, + Name, + NextDsn, + NextRenewal, + NextRetry, + OldName, + Origin, + Parameters, + Path, + Policy, PolicyType, - TotalSuccesses, - TotalFailures, - Date, - Uid, - UidValidity, - UidNext, + Property, + Protocol, + Query, + QueueId, + RangeFrom, + RangeTo, + Reason, + RemoteIp, + RemotePort, + Renewal, + ReportId, + Result, + Size, SourceAccountId, SourceMailboxId, SourceUid, + Spam, + SpamLearns, + SpanId, + SpfFail, + SpfNone, + SpfPass, + Status, + Strict, + Tls, + To, + Total, + TotalFailures, + TotalSuccesses, + Type, + Uid, + UidNext, + UidValidity, + Url, + Used, + ValidFrom, + ValidTo, + Value, + Version, } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] diff --git a/crates/utils/Cargo.toml b/crates/utils/Cargo.toml index 7219daca..3fbf878d 100644 --- a/crates/utils/Cargo.toml +++ b/crates/utils/Cargo.toml @@ -37,7 +37,6 @@ form_urlencoded = "1.1.0" [target.'cfg(unix)'.dependencies] privdrop = "0.5.3" -tracing-journald = "0.3" [features] test_mode = [] diff --git a/tests/Cargo.toml b/tests/Cargo.toml index 4304c274..df762f96 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -46,7 +46,6 @@ rayon = { version = "1.5.1" } flate2 = { version = "1.0.17", features = ["zlib"], default-features = false } serde = { version = "1.0", features = ["derive"]} serde_json = "1.0" -tracing-subscriber = { version = "0.3", features = ["env-filter"] } reqwest = { version = "0.12", default-features = false, features = ["rustls-tls-webpki-roots", "multipart", "http2"]} bytes = "1.4.0" futures = "0.3"