From 9655c97b8432b298be0660dc7b94730ef628cd14 Mon Sep 17 00:00:00 2001 From: Deluan Date: Mon, 28 Sep 2026 21:47:16 -0400 Subject: [PATCH] test(log): compute the expected source line instead of hard-coding it Signed-off-by: Deluan --- log/log_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/log/log_test.go b/log/log_test.go index 631b7c1aa..0e6628adb 100644 --- a/log/log_test.go +++ b/log/log_test.go @@ -5,8 +5,10 @@ import ( "context" "encoding/json" "errors" + "fmt" "net/http" "net/http/httptest" + "runtime" "testing" "time" @@ -94,9 +96,9 @@ var _ = Describe("Logger", func() { It("logs source file and line number, if requested", func() { SetLogSourceLine(true) + _, _, line, _ := runtime.Caller(0) Error("A crash happened") - // NOTE: This assertion breaks if the line number above changes - Expect(hook.LastEntry().Data[" source"]).To(ContainSubstring("/log/log_test.go:97")) + Expect(hook.LastEntry().Data[" source"]).To(ContainSubstring(fmt.Sprintf("/log/log_test.go:%d", line+1))) Expect(hook.LastEntry().Message).To(Equal("A crash happened")) })