@@ -3,7 +3,6 @@ package log_helper
33import (
44 "bytes"
55 stderrors "errors"
6- "os"
76 "strings"
87 "testing"
98 "time"
@@ -391,36 +390,32 @@ func TestCustomWriterNoStack(t *testing.T) {
391390 }
392391}
393392
394- // TestCustomWriterRelativePathInCwd tests relative path handling for files in cwd
393+ // TestCustomWriterRelativePathInCwd tests that paths are displayed as-is without manipulation
395394func TestCustomWriterRelativePathInCwd (t * testing.T ) {
396395 var buf bytes.Buffer
397396 writer := NewCustomWriter (& buf )
398397
399- // Get current directory for caller path
400- cwd , _ := os .Getwd ()
401- callerPath := cwd + "/test.go:42"
398+ // Test with a relative path
399+ callerPath := "test.go:42"
402400
403401 jsonLog := []byte (`{"level":"info","caller":"` + callerPath + `","message":"test"}` )
404402 n , err := writer .Write (jsonLog )
405403 require .NoError (t , err )
406404 require .Greater (t , n , 0 )
407405
408406 output := buf .String ()
409- // Should show relative path without full cwd
410- if strings .Contains (output , cwd ) {
411- t .Errorf ("Expected relative path, got full path in: %s" , output )
412- }
407+ // Should show path as-is
413408 if ! strings .Contains (output , "test.go:42" ) {
414- t .Errorf ("Expected relative file path, got: %s" , output )
409+ t .Errorf ("Expected caller path as-is , got: %s" , output )
415410 }
416411}
417412
418- // TestCustomWriterAbsolutePathOutsideCwd tests handling of paths outside cwd
413+ // TestCustomWriterAbsolutePathOutsideCwd tests that absolute paths are displayed as-is
419414func TestCustomWriterAbsolutePathOutsideCwd (t * testing.T ) {
420415 var buf bytes.Buffer
421416 writer := NewCustomWriter (& buf )
422417
423- // Use system path that's definitely outside cwd
418+ // Test with an absolute path
424419 callerPath := "/usr/lib/go/src/runtime/proc.go:285"
425420
426421 jsonLog := []byte (`{"level":"info","caller":"` + callerPath + `","message":"test"}` )
@@ -429,9 +424,9 @@ func TestCustomWriterAbsolutePathOutsideCwd(t *testing.T) {
429424 require .Greater (t , n , 0 )
430425
431426 output := buf .String ()
432- // Should keep absolute path for files outside cwd
427+ // Should show absolute path as-is
433428 if ! strings .Contains (output , callerPath ) {
434- t .Errorf ("Expected absolute path for file outside cwd , got: %s" , output )
429+ t .Errorf ("Expected absolute path as-is , got: %s" , output )
435430 }
436431}
437432
@@ -550,9 +545,6 @@ func TestNewCustomWriter(t *testing.T) {
550545 if writer .out != & buf {
551546 t .Error ("Expected output writer to be set" )
552547 }
553- if writer .cwd == "" {
554- t .Error ("Expected cwd to be set" )
555- }
556548}
557549
558550// TestCustomWriterConcurrent tests concurrent writes (no race conditions)
@@ -597,5 +589,5 @@ func TestCustomWriterQuotedStringValues(t *testing.T) {
597589 output := buf .String ()
598590 // Should handle quoted values properly
599591 require .Contains (t , output , "field=" , "Expected field in output, got: %s" , output )
600- require .Contains (t , output , `"quoted value"` , "Expected \" quoted value\" in output, got: %s" , output )
592+ require .Contains (t , output , `\ "quoted value\ "` , "Expected \\ \ " quoted value\\ \" in output, got: %s" , output )
601593}
0 commit comments