Skip to content
This repository has been archived by the owner on Feb 28, 2019. It is now read-only.

Commit

Permalink
Add check for nil service passed to route handler
Browse files Browse the repository at this point in the history
  • Loading branch information
m-sandusky committed Nov 10, 2017
1 parent 0880c87 commit 5589250
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions r2/service_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ func fetchRollupRuleHistory(s *service, r *http.Request) (data interface{}, err
type routeFunc func(s *service, r *http.Request) (data interface{}, err error)

func handleRoute(rf routeFunc, s *service, r *http.Request, namespace string) (interface{}, error) {
if r == nil {
return nil, errors.New("Nil request passed to handler")
if r == nil || s == nil {
return nil, errors.New("Must pass non nil service and request to route handler")
}
start := s.nowFn()
data, err := rf(s, r)
Expand Down
7 changes: 5 additions & 2 deletions r2/service_routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ func TestHandleRoute(t *testing.T) {

func TestHandleRouteNilRequest(t *testing.T) {
s := newTestService()
_, err := handleRoute(fetchNamespaces, s, nil, "ns")
require.EqualError(t, err, "Nil request passed to handler")
r := newTestGetRequest()
_, err1 := handleRoute(fetchNamespaces, s, nil, "ns")
_, err2 := handleRoute(fetchNamespaces, nil, r, "ns")
require.EqualError(t, err1, "Must pass non nil service and request to route handler")
require.EqualError(t, err2, "Must pass non nil service and request to route handler")
}
func TestFetchNamespacesSuccess(t *testing.T) {
expected := newNamespacesJSON(&rules.NamespacesView{})
Expand Down

0 comments on commit 5589250

Please sign in to comment.