Skip to content
Snippets Groups Projects
Commit de02f9d2 authored by OZGCloud's avatar OZGCloud
Browse files

fixed error

parent 37c64dd9
No related branches found
No related tags found
No related merge requests found
...@@ -31,23 +31,24 @@ import ( ...@@ -31,23 +31,24 @@ import (
"info-manager-proxy/internal/mock" "info-manager-proxy/internal/mock"
"net/http" "net/http"
"testing" "testing"
log "github.com/sirupsen/logrus" "log"
"github.com/sirupsen/logrus"
"go.elastic.co/ecslogrus"
) )
func TestRequestLoggingMiddleware(t *testing.T) { func TestRequestLoggingMiddleware(t *testing.T) {
logger := logrus.New()
logger.SetFormatter(&ecslogrus.Formatter{})
log.SetOutput(logger.Writer())
t.Run("should log request", func(t *testing.T) { t.Run("should log request", func(t *testing.T) {
logger.SetLevel(logrus.InfoLevel)
mock.SetUpGrpcServer() mock.SetUpGrpcServer()
SetUpHttpGateway() SetUpHttpGateway()
var buf bytes.Buffer var buf bytes.Buffer
log.SetOutput(&buf) log.SetOutput(&buf)
originalFlags := log.Baselog.Flags()
defer func() {
log.SetOutput(nil)
log.SetFlags(originalFlags)
}()
http.Get("http://localhost:8082/api/v1/information/testId") http.Get("http://localhost:8082/api/v1/information/testId")
logOutput := buf.String() logOutput := buf.String()
...@@ -56,18 +57,13 @@ func TestRequestLoggingMiddleware(t *testing.T) { ...@@ -56,18 +57,13 @@ func TestRequestLoggingMiddleware(t *testing.T) {
}) })
t.Run("should not log request", func(t *testing.T) { t.Run("should not log request", func(t *testing.T) {
logger.SetLevel(logrus.InfoLevel)
mock.SetUpGrpcServer() mock.SetUpGrpcServer()
SetUpHttpGateway() SetUpHttpGateway()
var buf bytes.Buffer var buf bytes.Buffer
log.SetOutput(&buf) log.SetOutput(&buf)
originalFlags := log.Baselog.Flags()
defer func() {
log.SetOutput(nil)
log.SetFlags(originalFlags)
}()
http.Get("http://localhost:8082/") http.Get("http://localhost:8082/")
logOutput := buf.String() logOutput := buf.String()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment