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

_RequestIdInContext_LoggerSetToContext   A

Complexity

Conditions 1

Size

Total Lines 16
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 14
nop 1
dl 0
loc 16
rs 9.7
c 0
b 0
f 0
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