mirror of
https://github.com/gabehf/Koito.git
synced 2026-03-07 13:38:15 -08:00
parent
ecae3699f1
commit
576f866ad7
1 changed files with 35 additions and 0 deletions
35
internal/logger/logger_test.go
Normal file
35
internal/logger/logger_test.go
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package logger
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
func TestInjectAndFromContext(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
testLogger := zerolog.New(&buf)
|
||||
|
||||
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||
|
||||
// Inject logger
|
||||
req = Inject(req, &testLogger)
|
||||
|
||||
// Retrieve logger
|
||||
l := FromContext(req.Context())
|
||||
|
||||
l.Info().Msg("hello")
|
||||
|
||||
output := buf.String()
|
||||
|
||||
if output == "" {
|
||||
t.Fatal("expected log output, got empty string")
|
||||
}
|
||||
|
||||
if !bytes.Contains([]byte(output), []byte("hello")) {
|
||||
t.Errorf("expected log to contain 'hello', got %s", output)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue