mirror of
https://github.com/gin-gonic/gin.git
synced 2026-06-04 09:48:17 +08:00
refactor(context): use http.StatusContinue constant instead of magic number 100
Replace magic number 100 with http.StatusContinue constant for better code clarity and maintainability in bodyAllowedForStatus function. Also fix typo in logger_test.go: colorForLantency -> colorForLatency Fixes #4489
This commit is contained in:
parent
81dba46872
commit
65c72a8059
@ -1056,6 +1056,7 @@ func (c *Context) requestHeader(key string) string {
|
||||
/************************************/
|
||||
|
||||
// bodyAllowedForStatus is a copy of http.bodyAllowedForStatus non-exported function.
|
||||
// Uses http.StatusContinue constant for better code clarity.
|
||||
func bodyAllowedForStatus(status int) bool {
|
||||
switch {
|
||||
case status >= http.StatusContinue && status < http.StatusOK:
|
||||
|
||||
@ -1031,6 +1031,7 @@ func TestContextGetCookie(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestContextBodyAllowedForStatus(t *testing.T) {
|
||||
assert.False(t, bodyAllowedForStatus(http.StatusContinue))
|
||||
assert.False(t, bodyAllowedForStatus(http.StatusProcessing))
|
||||
assert.False(t, bodyAllowedForStatus(http.StatusNoContent))
|
||||
assert.False(t, bodyAllowedForStatus(http.StatusNotModified))
|
||||
|
||||
@ -318,20 +318,20 @@ func TestColorForStatus(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestColorForLatency(t *testing.T) {
|
||||
colorForLantency := func(latency time.Duration) string {
|
||||
colorForLatency := func(latency time.Duration) string {
|
||||
p := LogFormatterParams{
|
||||
Latency: latency,
|
||||
}
|
||||
return p.LatencyColor()
|
||||
}
|
||||
|
||||
assert.Equal(t, white, colorForLantency(time.Duration(0)), "0 should be white")
|
||||
assert.Equal(t, white, colorForLantency(time.Millisecond*20), "20ms should be white")
|
||||
assert.Equal(t, green, colorForLantency(time.Millisecond*150), "150ms should be green")
|
||||
assert.Equal(t, cyan, colorForLantency(time.Millisecond*250), "250ms should be cyan")
|
||||
assert.Equal(t, yellow, colorForLantency(time.Millisecond*600), "600ms should be yellow")
|
||||
assert.Equal(t, magenta, colorForLantency(time.Millisecond*1500), "1.5s should be magenta")
|
||||
assert.Equal(t, red, colorForLantency(time.Second*3), "other things should be red")
|
||||
assert.Equal(t, white, colorForLatency(time.Duration(0)), "0 should be white")
|
||||
assert.Equal(t, white, colorForLatency(time.Millisecond*20), "20ms should be white")
|
||||
assert.Equal(t, green, colorForLatency(time.Millisecond*150), "150ms should be green")
|
||||
assert.Equal(t, cyan, colorForLatency(time.Millisecond*250), "250ms should be cyan")
|
||||
assert.Equal(t, yellow, colorForLatency(time.Millisecond*600), "600ms should be yellow")
|
||||
assert.Equal(t, magenta, colorForLatency(time.Millisecond*1500), "1.5s should be magenta")
|
||||
assert.Equal(t, red, colorForLatency(time.Second*3), "other things should be red")
|
||||
}
|
||||
|
||||
func TestResetColor(t *testing.T) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user