diff --git a/logger_test.go b/logger_test.go index f1d7fc3a60..33f66be229 100644 --- a/logger_test.go +++ b/logger_test.go @@ -10,6 +10,7 @@ import ( "fmt" "net/http" "testing" + "time" "github.com/stretchr/testify/assert" ) @@ -225,6 +226,34 @@ func TestLoggerWithConfigFormatting(t *testing.T) { } +func TestDefaultLogFormatter(t *testing.T) { + termFalseParam := LogFormatterParams{ + TimeStamp: time.Unix(1544173902, 0), + StatusCode: 200, + Latency: time.Second * 5, + ClientIP: "20.20.20.20", + Method: "GET", + Path: "/", + ErrorMessage: "", + IsTerm: false, + } + + termTrueParam := LogFormatterParams{ + TimeStamp: time.Unix(1544173902, 0), + StatusCode: 200, + Latency: time.Second * 5, + ClientIP: "20.20.20.20", + Method: "GET", + Path: "/", + ErrorMessage: "", + IsTerm: true, + } + + assert.Equal(t, "[GIN] 2018/12/07 - 18:11:42 | 200 | 5s | 20.20.20.20 | GET /\n", DefaultLogFormatter(termFalseParam)) + + assert.Equal(t, "[GIN] 2018/12/07 - 18:11:42 |\x1b[97;42m 200 \x1b[0m| 5s | 20.20.20.20 |\x1b[97;44m GET \x1b[0m /\n", DefaultLogFormatter(termTrueParam)) +} + func TestColorForMethod(t *testing.T) { assert.Equal(t, string([]byte{27, 91, 57, 55, 59, 52, 52, 109}), colorForMethod("GET"), "get should be blue") assert.Equal(t, string([]byte{27, 91, 57, 55, 59, 52, 54, 109}), colorForMethod("POST"), "post should be cyan")