Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix unittest #404

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading