mirror of https://github.com/matrix-org/go-neb.git
Browse Source
Merge pull request #100 from matrix-org/kegan/service-isolation
Merge pull request #100 from matrix-org/kegan/service-isolation
Prevent panicking code from taking down the entire processkegan/tests
Kegsay
8 years ago
committed by
GitHub
5 changed files with 91 additions and 5 deletions
-
4src/github.com/matrix-org/go-neb/goneb.go
-
20src/github.com/matrix-org/go-neb/matrix/worker.go
-
12src/github.com/matrix-org/go-neb/polling/polling.go
-
31src/github.com/matrix-org/go-neb/server/server.go
-
29src/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) |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue