Skip to content

Commit

Permalink
[coordinator] Fix panic in Ready endpoint for admin coordinator (#3335)
Browse files Browse the repository at this point in the history
  • Loading branch information
linasm authored Mar 8, 2021
1 parent 73a98e6 commit b91dd5c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/query/api/v1/handler/ready.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,12 @@ func (h *ReadyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

var (
var namespaces m3.ClusterNamespaces
if h.clusters != nil {
namespaces = h.clusters.ClusterNamespaces()
result = &readyResult{}
)
}

result := &readyResult{}
for _, ns := range namespaces {
attrs := ns.Options().Attributes()
nsResult := readyResultNamespace{
Expand Down
25 changes: 25 additions & 0 deletions src/query/api/v1/handler/ready_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,28 @@ func TestReadyHandler(t *testing.T) {
})
}
}

func TestReadyHandlerNoClusters(t *testing.T) {
ctrl := xtest.NewController(t)
defer ctrl.Finish()

opts := options.EmptyHandlerOptions()
readyHandler := NewReadyHandler(opts)

w := httptest.NewRecorder()
url := ReadyURL
req := httptest.NewRequest(ReadyHTTPMethod, url, nil)

readyHandler.ServeHTTP(w, req)

resp := w.Result()
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
assert.NoError(t, err)
assert.Equal(t, http.StatusOK, resp.StatusCode)

expected := "{}"
actual := xtest.MustPrettyJSONString(t, string(body))

assert.Equal(t, expected, actual, xtest.Diff(expected, actual))
}

0 comments on commit b91dd5c

Please sign in to comment.