Skip to content

Commit

Permalink
(maint) update logged? for better messaging
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jonathannewman committed Jun 28, 2024
1 parent c063c49 commit 09faca8
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions test/puppetlabs/trapperkeeper/testutils/logging.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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]
(let [items? (seq items)]
(if (and items? (or disable-single-line-match-restriction (empty? (rest items?))))
true
(if items?
(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?)
Expand Down

0 comments on commit 09faca8

Please sign in to comment.