Test Failed
Push — master ( 3bbb09...a6d785 )
by Igor
03:12
created

internal/server/middleware/ContextLogger_test.go   A

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 23
dl 0
loc 29
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A middleware.TestContextualLoggerHandler_ServeHTTP_RequestIdInContext_LoggerSetToContext 0 16 1
1
package middleware
2
3
import (
4
	"context"
5
	"net/http"
6
	"net/http/httptest"
7
	"testing"
8
9
	httpmock "github.com/muonsoft/openapi-mock/test/mocks/http"
10
	"github.com/sirupsen/logrus/hooks/test"
11
	"github.com/stretchr/testify/mock"
12
)
13
14
func TestContextualLoggerHandler_ServeHTTP_RequestIdInContext_LoggerSetToContext(t *testing.T) {
15
	request, _ := http.NewRequest("GET", "/", nil)
16
	ctx := context.WithValue(context.Background(), requestIDKey, "00000000-0000-0000-0000-000000000000")
17
	request = request.WithContext(ctx)
18
	recorder := httptest.NewRecorder()
19
	logger, _ := test.NewNullLogger()
20
	nextHandler := httpmock.Handler{}
21
	handler := NewContextLogger(logger, &nextHandler)
22
	nextHandler.
23
		On("ServeHTTP", mock.Anything, mock.Anything).
24
		Return(nil).
25
		Once()
26
27
	handler.ServeHTTP(recorder, request)
28
29
	nextHandler.AssertExpectations(t)
30
}
31