aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/_nuts/github.com/go-martini/martini/recovery_test.go
diff options
context:
space:
mode:
authorTeddy Wing2015-06-06 19:25:17 -0400
committerTeddy Wing2015-06-06 19:25:17 -0400
commit1135764727f3dc525d0f674c784edbc81cc786f3 (patch)
tree5c402c88d3a07a3cde84237ead5829bda28f3e25 /vendor/_nuts/github.com/go-martini/martini/recovery_test.go
downloadNew-House-on-the-Block-1135764727f3dc525d0f674c784edbc81cc786f3.tar.bz2
Initial commit. Install coinbase-go.
* Use nut for vendored dependencies * Install coinbase-go to interact with the Coinbase API
Diffstat (limited to 'vendor/_nuts/github.com/go-martini/martini/recovery_test.go')
-rw-r--r--vendor/_nuts/github.com/go-martini/martini/recovery_test.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/vendor/_nuts/github.com/go-martini/martini/recovery_test.go b/vendor/_nuts/github.com/go-martini/martini/recovery_test.go
new file mode 100644
index 0000000..17e2e01
--- /dev/null
+++ b/vendor/_nuts/github.com/go-martini/martini/recovery_test.go
@@ -0,0 +1,49 @@
+package martini
+
+import (
+ "bytes"
+ "log"
+ "net/http"
+ "net/http/httptest"
+ "testing"
+)
+
+func Test_Recovery(t *testing.T) {
+ buff := bytes.NewBufferString("")
+ recorder := httptest.NewRecorder()
+
+ setENV(Dev)
+ m := New()
+ // replace log for testing
+ m.Map(log.New(buff, "[martini] ", 0))
+ m.Use(func(res http.ResponseWriter, req *http.Request) {
+ res.Header().Set("Content-Type", "unpredictable")
+ })
+ m.Use(Recovery())
+ m.Use(func(res http.ResponseWriter, req *http.Request) {
+ panic("here is a panic!")
+ })
+ m.ServeHTTP(recorder, (*http.Request)(nil))
+ expect(t, recorder.Code, http.StatusInternalServerError)
+ expect(t, recorder.HeaderMap.Get("Content-Type"), "text/html")
+ refute(t, recorder.Body.Len(), 0)
+ refute(t, len(buff.String()), 0)
+}
+
+func Test_Recovery_ResponseWriter(t *testing.T) {
+ recorder := httptest.NewRecorder()
+ recorder2 := httptest.NewRecorder()
+
+ setENV(Dev)
+ m := New()
+ m.Use(Recovery())
+ m.Use(func(c Context) {
+ c.MapTo(recorder2, (*http.ResponseWriter)(nil))
+ panic("here is a panic!")
+ })
+ m.ServeHTTP(recorder, (*http.Request)(nil))
+
+ expect(t, recorder2.Code, http.StatusInternalServerError)
+ expect(t, recorder2.HeaderMap.Get("Content-Type"), "text/html")
+ refute(t, recorder2.Body.Len(), 0)
+}