Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
antragraum-proxy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OZG-Cloud
app
antragraum-proxy
Commits
8d1202fd
Commit
8d1202fd
authored
5 months ago
by
OZGCloud
Browse files
Options
Downloads
Patches
Plain Diff
fixed test
parent
f63b91ca
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
internal/server/grpc_router.go
+1
-1
1 addition, 1 deletion
internal/server/grpc_router.go
internal/server/middleware_test.go
+19
-15
19 additions, 15 deletions
internal/server/middleware_test.go
with
20 additions
and
16 deletions
internal/server/grpc_router.go
+
1
−
1
View file @
8d1202fd
...
...
@@ -95,7 +95,7 @@ func createRueckfrageClient(grpcAddress string) (pb.AntragraumServiceClient, fun
target
:=
GetGrpcServerUrl
(
grpcAddress
,
conf
)
conn
,
err
:=
grpc
.
NewClient
(
target
,
grpc
.
WithTransportCredentials
(
insecure
.
NewCredentials
()))
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Error
(
"rueckfrage router failed to route: %v"
,
err
)
log
.
WithError
(
err
)
.
Error
(
fmt
.
Sprintf
(
"rueckfrage router failed to route: %v"
,
err
)
)
return
nil
,
nil
,
errors
.
New
(
"rueckfrage router failed to route"
)
}
...
...
This diff is collapsed.
Click to expand it.
internal/server/middleware_test.go
+
19
−
15
View file @
8d1202fd
...
...
@@ -31,46 +31,50 @@ import (
"github.com/stretchr/testify/assert"
"net/http"
"testing"
"log"
"github.com/sirupsen/logrus"
"go.elastic.co/ecslogrus"
)
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
)
{
logger
.
SetLevel
(
logrus
.
DebugLevel
)
mock
.
SetUpGrpcServer
()
SetUpGrpcRouter
()
SetUpHttpGateway
()
var
buf
bytes
.
Buffer
logger
.
BaseLogger
.
SetOutput
(
&
buf
)
originalFlags
:=
logger
.
BaseLogger
.
Flags
()
defer
func
()
{
logger
.
BaseLogger
.
SetOutput
(
nil
)
logger
.
BaseLogger
.
SetFlags
(
originalFlags
)
}()
jsonData
:=
[]
byte
(
`{"postfachId": "testPostfachId"}`
)
req
,
_
:=
http
.
NewRequest
(
"POST"
,
"http://localhost:8082/api/v1/rueckfragen"
,
bytes
.
NewBuffer
(
jsonData
))
req
.
Header
.
Set
(
GrpcAddressHeader
,
"localhost"
)
var
buf
bytes
.
Buffer
log
.
SetOutput
(
&
buf
)
defer
func
()
{
log
.
SetOutput
(
nil
)
}()
client
:=
&
http
.
Client
{}
client
.
Do
(
req
)
logOutput
:=
buf
.
String
()
assert
.
Contains
(
t
,
logOutput
,
"received POST request for /api/v1/rueckfragen with body: {
\"
postfachId
\"
:
\"
testPostfachId
\"
}"
)
assert
.
Contains
(
t
,
logOutput
,
"successfully handled POST request for /api/v1/rueckfragen with body: {
\"
postfachId
\"
:
\"
testPostfachId
\"
}"
)
assert
.
Contains
(
t
,
"successfully handled POST request for /api/v1/rueckfragen with body: {
\"
postfachId
\"
:
\"
testPostfachId
\"
}"
,
logOutput
)
})
t
.
Run
(
"should not log request"
,
func
(
t
*
testing
.
T
)
{
logger
.
SetLevel
(
logrus
.
InfoLevel
)
mock
.
SetUpGrpcServer
()
SetUpHttpGateway
()
var
buf
bytes
.
Buffer
log
ger
.
BaseLogger
.
SetOutput
(
&
buf
)
log
.
SetOutput
(
&
buf
)
originalFlags
:=
logger
.
BaseLogger
.
Flags
()
defer
func
()
{
logger
.
BaseLogger
.
SetOutput
(
nil
)
logger
.
BaseLogger
.
SetFlags
(
originalFlags
)
log
.
SetOutput
(
nil
)
}()
http
.
Get
(
"http://localhost:8082/"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment