mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-15 20:02:15 +01:00
slighty improvement of logging (#6)
This commit is contained in:
@@ -6,8 +6,40 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/thecodingmachine/gotenberg/app/converter"
|
||||
|
||||
"github.com/satori/go.uuid"
|
||||
)
|
||||
|
||||
func TestWithRequestID(t *testing.T) {
|
||||
requestID := uuid.NewV4().String()
|
||||
req := WithRequestID(httptest.NewRequest(http.MethodPost, "/", nil), requestID)
|
||||
if ID, _ := req.Context().Value(requestIDKey).(string); ID != requestID {
|
||||
t.Errorf("Context returned a wrong converter: got '%s' want '%s'", ID, requestID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequestIDNotFoundError(t *testing.T) {
|
||||
err := &requestIDNotFoundError{}
|
||||
if err.Error() != requestIDNotFoundErrorMessage {
|
||||
t.Errorf("Error returned a wrong message: got '%s' want '%s'", err.Error(), requestIDNotFoundErrorMessage)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetRequestID(t *testing.T) {
|
||||
req := httptest.NewRequest(http.MethodPost, "/", nil)
|
||||
|
||||
// case 1: uses a request without a request ID entry in its context.
|
||||
if _, err := GetRequestID(req); err == nil {
|
||||
t.Error("Context should not have a request ID entry")
|
||||
}
|
||||
|
||||
// case 2: uses a request with a request ID entry in its context.
|
||||
req = WithRequestID(req, uuid.NewV4().String())
|
||||
if _, err := GetRequestID(req); err != nil {
|
||||
t.Error("Context should have a request ID entry")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithConverter(t *testing.T) {
|
||||
req := WithConverter(httptest.NewRequest(http.MethodPost, "/", nil), &converter.Converter{})
|
||||
if c, _ := req.Context().Value(converterKey).(*converter.Converter); c == nil {
|
||||
@@ -15,6 +47,13 @@ func TestWithConverter(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestConverterNotFoundError(t *testing.T) {
|
||||
err := &converterNotFoundError{}
|
||||
if err.Error() != converterNotFoundErrorMessage {
|
||||
t.Errorf("Error returned a wrong message: got '%s' want '%s'", err.Error(), converterNotFoundErrorMessage)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetConverter(t *testing.T) {
|
||||
req := httptest.NewRequest(http.MethodPost, "/", nil)
|
||||
|
||||
@@ -38,6 +77,13 @@ func TestWithResultFilePath(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestResultFilePathNotFoundError(t *testing.T) {
|
||||
err := &resultFilePathNotFoundError{}
|
||||
if err.Error() != resultFilePathNotFoundErrorMessage {
|
||||
t.Errorf("Error returned a wrong message: got '%s' want '%s'", err.Error(), resultFilePathNotFoundErrorMessage)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetResultFilePath(t *testing.T) {
|
||||
req := httptest.NewRequest(http.MethodPost, "/", nil)
|
||||
|
||||
@@ -52,17 +98,3 @@ func TestGetResultFilePath(t *testing.T) {
|
||||
t.Error("Context should have a result file path entry")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConverterNotFoundError(t *testing.T) {
|
||||
err := &converterNotFoundError{}
|
||||
if err.Error() != converterNotFoundErrorMessage {
|
||||
t.Errorf("Error returned a wrong message: got '%s' want '%s'", err.Error(), converterNotFoundErrorMessage)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResultFilePathNotFoundError(t *testing.T) {
|
||||
err := &resultFilePathNotFoundError{}
|
||||
if err.Error() != resultFilePathNotFoundErrorMessage {
|
||||
t.Errorf("Error returned a wrong message: got '%s' want '%s'", err.Error(), resultFilePathNotFoundErrorMessage)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user