mirror of
https://github.com/sosedoff/pgweb.git
synced 2024-12-15 03:36:33 +03:00
afe431c94d
* Add request-id logging * Missing test file * Add option to log forwarded user information if available via X-Forwarded-Header * Format
32 lines
713 B
Go
32 lines
713 B
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func Test_getRequestID(t *testing.T) {
|
|
examples := []struct {
|
|
headers map[string]string
|
|
result string
|
|
}{
|
|
{map[string]string{}, ""},
|
|
{map[string]string{"X-Request-ID": "foo"}, "foo"},
|
|
{map[string]string{"x-request-id": "foo"}, "foo"},
|
|
{map[string]string{"x-request-id": "foo"}, "foo"},
|
|
{map[string]string{"x-request-id": "foo", "x-amzn-trace-id": "amz"}, "foo"},
|
|
}
|
|
|
|
for _, ex := range examples {
|
|
req := &http.Request{Header: http.Header{}}
|
|
for k, v := range ex.headers {
|
|
req.Header.Set(k, v)
|
|
}
|
|
|
|
assert.Equal(t, ex.result, getRequestID(&gin.Context{Request: req}))
|
|
}
|
|
}
|