mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-31 04:30:44 +00:00
Upgrade gin-gonic to latest master, fix compatibility issues
This commit is contained in:
+17
-30
@@ -6,51 +6,38 @@ package gin
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"log"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// TestPanicInHandler assert that panic has been recovered.
|
||||
func TestPanicInHandler(t *testing.T) {
|
||||
// SETUP
|
||||
log.SetOutput(bytes.NewBuffer(nil)) // Disable panic logs for testing
|
||||
r := New()
|
||||
r.Use(Recovery())
|
||||
r.GET("/recovery", func(_ *Context) {
|
||||
buffer := new(bytes.Buffer)
|
||||
router := New()
|
||||
router.Use(RecoveryWithWriter(buffer))
|
||||
router.GET("/recovery", func(_ *Context) {
|
||||
panic("Oupps, Houston, we have a problem")
|
||||
})
|
||||
|
||||
// RUN
|
||||
w := PerformRequest(r, "GET", "/recovery")
|
||||
|
||||
// restore logging
|
||||
log.SetOutput(os.Stderr)
|
||||
|
||||
if w.Code != 500 {
|
||||
t.Errorf("Response code should be Internal Server Error, was: %s", w.Code)
|
||||
}
|
||||
w := performRequest(router, "GET", "/recovery")
|
||||
// TEST
|
||||
assert.Equal(t, w.Code, 500)
|
||||
assert.Contains(t, buffer.String(), "GET /recovery")
|
||||
assert.Contains(t, buffer.String(), "Oupps, Houston, we have a problem")
|
||||
assert.Contains(t, buffer.String(), "TestPanicInHandler")
|
||||
}
|
||||
|
||||
// TestPanicWithAbort assert that panic has been recovered even if context.Abort was used.
|
||||
func TestPanicWithAbort(t *testing.T) {
|
||||
// SETUP
|
||||
log.SetOutput(bytes.NewBuffer(nil))
|
||||
r := New()
|
||||
r.Use(Recovery())
|
||||
r.GET("/recovery", func(c *Context) {
|
||||
router := New()
|
||||
router.Use(RecoveryWithWriter(nil))
|
||||
router.GET("/recovery", func(c *Context) {
|
||||
c.AbortWithStatus(400)
|
||||
panic("Oupps, Houston, we have a problem")
|
||||
})
|
||||
|
||||
// RUN
|
||||
w := PerformRequest(r, "GET", "/recovery")
|
||||
|
||||
// restore logging
|
||||
log.SetOutput(os.Stderr)
|
||||
|
||||
w := performRequest(router, "GET", "/recovery")
|
||||
// TEST
|
||||
if w.Code != 500 {
|
||||
t.Errorf("Response code should be Bad request, was: %s", w.Code)
|
||||
}
|
||||
assert.Equal(t, w.Code, 400)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user