Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(maint) update logged? for better output, prepare for release #317

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
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]
(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?)
Expand Down
Loading