Browse Source

Tests and comments

kegan/service-isolation
Kegan Dougal 8 years ago
parent
commit
236c97d279
  1. 2
      src/github.com/matrix-org/go-neb/polling/polling.go
  2. 29
      src/github.com/matrix-org/go-neb/server/server_test.go

2
src/github.com/matrix-org/go-neb/polling/polling.go

@ -74,6 +74,8 @@ func pollLoop(service types.Service, ts int64) {
})
defer func() {
// Kill the poll loop entirely as it is likely that whatever made us panic will
// make us panic again. We can whine bitterly about it though.
if r := recover(); r != nil {
logger.WithField("panic", r).Errorf(
"pollLoop panicked!\n%s", debug.Stack(),

29
src/github.com/matrix-org/go-neb/server/server_test.go

@ -0,0 +1,29 @@
package server
import (
"net/http"
"net/http/httptest"
"testing"
)
func TestProtect(t *testing.T) {
mockWriter := httptest.NewRecorder()
mockReq, _ := http.NewRequest("GET", "http://example.com/foo", nil)
h := Protect(func(w http.ResponseWriter, req *http.Request) {
var array []string
w.Write([]byte(array[5])) // NPE
})
h(mockWriter, mockReq)
expectCode := 500
if mockWriter.Code != expectCode {
t.Errorf("TestProtect wanted HTTP status %d, got %d", expectCode, mockWriter.Code)
}
expectBody := `{"message":"Internal Server Error"}`
actualBody := mockWriter.Body.String()
if actualBody != expectBody {
t.Errorf("TestProtect wanted body %s, got %s", expectBody, actualBody)
}
}
Loading…
Cancel
Save