Skip to content

Commit

Permalink
Merge pull request #404 from askuy/feature/slowlog20240625
Browse files Browse the repository at this point in the history
fix unittest
  • Loading branch information
askuy authored Jun 26, 2024
2 parents 7c1de32 + cabebd4 commit a2c0444
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions server/egin/interceptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package egin
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net"
"net/http"
Expand Down Expand Up @@ -42,15 +41,15 @@ func TestPanicInHandler(t *testing.T) {
// 调用触发panic的接口
w := performRequest(router, "GET", "/recovery")
logged, err := os.ReadFile(path.Join(logger.ConfigDir(), logger.ConfigName()))
fmt.Printf("logged--------------->"+"%+v\n", string(logged))
assert.NoError(t, err)
// 虽然程序里返回200,只要panic就会为500
assert.Equal(t, http.StatusInternalServerError, w.Code)
var m map[string]interface{}
n := strings.Index(string(logged), "{")
err1 := json.Unmarshal(logged[n:], &m)
assert.NoError(t, err1)
assert.Contains(t, m["event"], `recover`)
//assert.Contains(t, m["event"], `recover`)
assert.Contains(t, m["lv"], `error`)
assert.Contains(t, string(logged), "we have a panic")
assert.Contains(t, m["method"], `GET./recovery`)
assert.Contains(t, string(logged), "500")
Expand Down Expand Up @@ -86,7 +85,6 @@ func TestPanicInCustomHandler(t *testing.T) {
// 调用触发panic的接口
w := performRequest(router, "GET", "/recovery")
logged, err := os.ReadFile(path.Join(logger.ConfigDir(), logger.ConfigName()))
fmt.Printf("logged--------------->%+v\n", string(logged))
assert.NoError(t, err)
// TEST
assert.Equal(t, http.StatusInternalServerError, w.Code)
Expand All @@ -95,7 +93,7 @@ func TestPanicInCustomHandler(t *testing.T) {
n := strings.Index(string(logged), "{")
err1 := json.Unmarshal(logged[n:], &m)
assert.NoError(t, err1)
assert.Equal(t, m["event"], `recover`)
assert.Equal(t, m["lv"], `error`)
assert.Equal(t, m["error"], panicMessage)
assert.Equal(t, m["method"], `GET./recovery`)
assert.Contains(t, m["stack"], t.Name())
Expand Down

0 comments on commit a2c0444

Please sign in to comment.