From 00ff3fdc82b1eb5abbe2231b0d3bf6c2798526d6 Mon Sep 17 00:00:00 2001 From: jonathannewman Date: Fri, 28 Jun 2024 08:46:07 -0700 Subject: [PATCH 1/2] (maint) update `logged?` for better messaging Update the `logged?` function to only emit messages when there are multiple statements when they aren't expected, and also clean up the output to be more useful. --- test/puppetlabs/trapperkeeper/testutils/logging.clj | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/puppetlabs/trapperkeeper/testutils/logging.clj b/test/puppetlabs/trapperkeeper/testutils/logging.clj index 60a60e8..9b72276 100644 --- a/test/puppetlabs/trapperkeeper/testutils/logging.clj +++ b/test/puppetlabs/trapperkeeper/testutils/logging.clj @@ -318,6 +318,7 @@ (swap! destination# conj event#))] ~@body))))) + (s/defn ^{:always-validate true} logged? ([msg-or-pred] (logged? msg-or-pred nil nil)) ([msg-or-pred maybe-level] (logged? msg-or-pred maybe-level nil)) @@ -329,9 +330,14 @@ (let [match? (cond (ifn? msg-or-pred) msg-or-pred (string? msg-or-pred) #(= msg-or-pred (:message %)) :else #(re-find msg-or-pred (:message %))) - one-element-if-specified? #(if (and (seq %) (or disable-single-line-match-restriction (empty? (rest %)))) - true - (println "\n`logged?` warning: multiple log line matches found, but this arity expects only one match, returning false. Found matches: " % "\n")) + one-element-if-specified? (fn [items] + (if (seq items) + (if (or disable-single-line-match-restriction (empty? (rest items))) + true + (do + (println "\n`logged?` warning: multiple log line matches found, but this arity expects only one match, returning false. Found matches: \n" (pr-str (map :message items)) "\n") + false)) + false)) correct-level? #(or (nil? maybe-level) (= maybe-level (:level %)))] (->> (map event->map @*test-log-events*) (filter correct-level?) From 4ec8d1c3a3fa97475ab461a2e6832ea75a1a6610 Mon Sep 17 00:00:00 2001 From: jonathannewman Date: Fri, 28 Jun 2024 08:47:04 -0700 Subject: [PATCH 2/2] (maint) prepare for release --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 95019f6..d1ac331 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 3.3.3 +* update `logged?` to not emit an incorrect message when there are no matches, and clean up the output from multiple unexpected matches. + ## 3.3.2 * this is a minor release changing a test utility * adds a new arity to `logged?` that removes the restriction that only one log line must match the pattern, adds printing to the function and repo documentation to make users aware of this single line match restriction