mirror of
https://github.com/l5yth/potato-mesh.git
synced 2026-08-09 18:33:02 +02:00
Add coverage for debug logging on messages without sender (#86)
* Add debug logging spec for messages without sender * Route debug logging through Kernel.warn * Relax debug log matchers
This commit is contained in:
+3
-3
@@ -115,8 +115,8 @@ def query_messages(limit)
|
||||
rows.each do |r|
|
||||
if DEBUG && (r["from_id"].nil? || r["from_id"].to_s.empty?)
|
||||
raw = db.execute("SELECT * FROM messages WHERE id = ?", [r["id"]]).first
|
||||
warn "[debug] messages row before join: #{raw.inspect}"
|
||||
warn "[debug] row after join: #{r.inspect}"
|
||||
Kernel.warn "[debug] messages row before join: #{raw.inspect}"
|
||||
Kernel.warn "[debug] row after join: #{r.inspect}"
|
||||
end
|
||||
node = {}
|
||||
r.keys.each do |k|
|
||||
@@ -126,7 +126,7 @@ def query_messages(limit)
|
||||
r["snr"] = r.delete("msg_snr")
|
||||
r["node"] = node unless node.empty?
|
||||
if DEBUG && (r["from_id"].nil? || r["from_id"].to_s.empty?)
|
||||
warn "[debug] row after processing: #{r.inspect}"
|
||||
Kernel.warn "[debug] row after processing: #{r.inspect}"
|
||||
end
|
||||
end
|
||||
rows
|
||||
|
||||
@@ -488,5 +488,40 @@ RSpec.describe "Potato Mesh Sinatra app" do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when DEBUG logging is enabled" do
|
||||
it "logs diagnostics for messages missing a sender" do
|
||||
stub_const("DEBUG", true)
|
||||
allow(Kernel).to receive(:warn)
|
||||
|
||||
message_id = 987_654
|
||||
payload = {
|
||||
"packet_id" => message_id,
|
||||
"from_id" => " ",
|
||||
"text" => "debug logging",
|
||||
}
|
||||
|
||||
post "/api/messages", payload.to_json, auth_headers
|
||||
expect(last_response).to be_ok
|
||||
expect(JSON.parse(last_response.body)).to eq("status" => "ok")
|
||||
|
||||
get "/api/messages"
|
||||
expect(last_response).to be_ok
|
||||
|
||||
expect(Kernel).to have_received(:warn).with(
|
||||
a_string_matching(/\[debug\] messages row before join: .*"id"\s*=>\s*#{message_id}/),
|
||||
)
|
||||
expect(Kernel).to have_received(:warn).with(
|
||||
a_string_matching(/\[debug\] row after join: .*"id"\s*=>\s*#{message_id}/),
|
||||
)
|
||||
expect(Kernel).to have_received(:warn).with(
|
||||
a_string_matching(/\[debug\] row after processing: .*"id"\s*=>\s*#{message_id}/),
|
||||
)
|
||||
|
||||
messages = JSON.parse(last_response.body)
|
||||
expect(messages.size).to eq(1)
|
||||
expect(messages.first["from_id"]).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user