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

Commit

Permalink
Adds check for nil request and adds test
Browse files Browse the repository at this point in the history
  • Loading branch information
m-sandusky committed Nov 10, 2017
1 parent b64bbe9 commit 0880c87
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions r2/service_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package r2

import (
"errors"
"fmt"
"net/http"
"time"
Expand Down Expand Up @@ -250,6 +251,9 @@ 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")
}
start := s.nowFn()
data, err := rf(s, r)
s.metrics.recordMetric(r.RequestURI, r.Method, namespace, time.Since(start), err)
Expand Down
6 changes: 6 additions & 0 deletions r2/service_routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ func TestHandleRoute(t *testing.T) {
require.NoError(t, err)
require.Equal(t, expected, actual)
}

func TestHandleRouteNilRequest(t *testing.T) {
s := newTestService()
_, err := handleRoute(fetchNamespaces, s, nil, "ns")
require.EqualError(t, err, "Nil request passed to handler")
}
func TestFetchNamespacesSuccess(t *testing.T) {
expected := newNamespacesJSON(&rules.NamespacesView{})
actual, err := fetchNamespaces(newTestService(), nil)
Expand Down

0 comments on commit 0880c87

Please sign in to comment.