49 lines
892 B
Go
49 lines
892 B
Go
|
package eia
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"net/http"
|
||
|
"net/url"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/rs/zerolog"
|
||
|
)
|
||
|
|
||
|
func Test_newLoggingMiddleware(t *testing.T) {
|
||
|
logger := zerolog.New(zerolog.NewTestWriter(t))
|
||
|
|
||
|
tests := []struct {
|
||
|
name string
|
||
|
request *http.Request
|
||
|
wantErr bool
|
||
|
}{
|
||
|
{
|
||
|
name: "Test empty request",
|
||
|
request: &http.Request{},
|
||
|
wantErr: true,
|
||
|
},
|
||
|
{
|
||
|
name: "Test valid request",
|
||
|
request: &http.Request{
|
||
|
Method: "GET",
|
||
|
URL: &url.URL{
|
||
|
Scheme: "https",
|
||
|
Host: "test.test",
|
||
|
Path: "/test",
|
||
|
},
|
||
|
},
|
||
|
wantErr: false,
|
||
|
},
|
||
|
}
|
||
|
|
||
|
for _, tt := range tests {
|
||
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
middlewareFunc := newLoggingMiddleware(&logger, zerolog.TraceLevel)
|
||
|
err := middlewareFunc(context.Background(), tt.request)
|
||
|
if (err != nil) != tt.wantErr {
|
||
|
t.Errorf("Test %s had unexpected error: %s", tt.name, err.Error())
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|